Simple Python Solution


  • 0
    Y
    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
                else:
                    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.