- https://leetcode.com/problems/contains-duplicate-ii/
- https://leetcode-cn.com/problems/contains-duplicate-ii/
时间复杂度:O(n)
空间复杂度:O(min(n, k))
class Solution:
def containsNearbyDuplicate(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: bool
"""
memo = {}
for index, value in enumerate(nums):
if value in memo and index - memo[value] <= k:
return True
memo[value] = index
return False