contains-duplicate

This commit is contained in:
Gleb Koval 2021-11-05 12:53:01 +00:00
parent b2132c4a69
commit 93fcca2976
No known key found for this signature in database
GPG Key ID: 7C89CDC822F8392B
1 changed files with 14 additions and 0 deletions

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
}