版权声明:原创勿转 https://cloud.tencent.com/developer/article/1412915
思路
用一个hash保存出现过的元素
code
代码语言:javascript复制func containsDuplicate(nums []int) bool {
if len(nums) < 2 {
return false
}
m := make(map[int]bool)
for _, v := range nums {
_, ok := m[v]
if ok {
return true
}
m[v] = true
}
return false
}