add new solutions
This commit is contained in:
parent
e1b702657c
commit
59b71480d4
11 changed files with 343 additions and 0 deletions
18
solutions/2/q219/solution.go
Normal file
18
solutions/2/q219/solution.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package q219
|
||||
|
||||
func containsNearbyDuplicate(nums []int, k int) bool {
|
||||
seen := make(map[int]struct{}, k)
|
||||
|
||||
for i, num := range nums {
|
||||
if _, ok := seen[num]; ok {
|
||||
return true
|
||||
}
|
||||
seen[num] = struct{}{}
|
||||
if i >= k {
|
||||
delete(seen, nums[i-k])
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var _ = containsNearbyDuplicate
|
||||
Loading…
Add table
Add a link
Reference in a new issue