Simple Python Solution

  • 0
    def containsNearbyDuplicate(self, nums, k):
            dic = {}
            for i,v in enumerate(nums):
                if i > k:
                    dic.pop(nums[i-k-1], None)
                if v in dic:
                    return True
                    dic[v] = 1
            return False

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.