contains-duplicate

This commit is contained in:
2021-11-05 12:53:01 +00:00
parent b2132c4a69
commit 93fcca2976

14
contains-duplicate/sol.go Normal file
View File

@@ -0,0 +1,14 @@
package main
// Time: O(n)
// Space: O(n)
func containsDuplicate(nums []int) bool {
exists := make(map[int]bool)
for _, num := range nums {
if _, ok := exists[num]; ok {
return true
}
exists[num] = true
}
return false
}