Untitled

Anonymous
plain_text
09/22/2022 2:17 AM
664 B
24
Indexable
class Solution(object):
    def containsNearbyDuplicate(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: bool
        """
        hashmap = defaultdict(int)
        
        for i in range(len(nums)):
            
            if nums[i] in hashmap and (i - hashmap[nums[i]]) <= k:
                    return True
            else:
                
                hashmap[nums[i]] = i
                
        return False
                
            
Editor is loading...