Created
August 2, 2015 02:52
-
-
Save ravichandrae/5b8e7c2f9110623053ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def containsNearbyDuplicate(nums, k): | |
index_map = {} | |
for i in range(len(nums)): | |
if nums[i] in index_map: | |
if i - index_map[nums[i]] > k: | |
index_map[nums[i]] = i | |
else: | |
return True | |
else: | |
index_map[nums[i]] = i | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment