contains-duplicate
This commit is contained in:
14
contains-duplicate/sol.go
Normal file
14
contains-duplicate/sol.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user