版权声明:原创勿转 https://blog.csdn.net/anakinsun/article/details/89043350
思路
用一个hash保存出现过的元素
code
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
}
更多内容请移步我的repo: https://github.com/anakin/golang-leetcode