Closed allensuvorov closed 1 year ago
func containsNearbyDuplicate(nums []int, k int) bool { hm := map[int]int{} for i, v := range nums { if _, ok := hm[v]; !ok { hm[v] = i continue } if i - hm[v] <= k { return true } else { hm[v] = i } } return false }
Looking for a better solution, than nested loop over a subarray.