luoheng
10/7/2019 - 3:33 AM

containsNearbyDuplicate

func containsNearbyDuplicate(nums []int, k int) bool {
    c := map[int]int{}
    for i, n := range nums {
        if _, ok := c[n]; ok && i - c[n] <= k {
            return true
        }
        c[n] = i
    }
    return false
}