Contains Duplicate II
ID: 219; easy
Last updated
Was this helpful?
Was this helpful?
func containsNearbyDuplicate(nums []int, k int) bool {
m := make(map[int]bool, len(nums))
for i,v := range nums {
if _, found := m[v]; found {
return true
}
m[v] = true
if len(m) == k+1 {
delete(m, nums[i-k])
}
}
return false
}