contains-duplicate
This commit is contained in:
parent
b2132c4a69
commit
93fcca2976
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue