Untitled
unknown
plain_text
3 years ago
498 B
10
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...