Golang Leetcode 217. Contains Duplicate.go

版权声明:原创勿转 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

猜你喜欢

转载自blog.csdn.net/anakinsun/article/details/89043350