class Solution:
def containsNearbyDuplicate(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: bool
"""
mydict={}
for i in range(len(nums)):
n=nums[i]
if n in mydict:
if i-mydict[n]<=k:
return True
else:
mydict[n]=i
else:
mydict[n]=i
return False
python leetcode 219. Contains Duplicate II
最新推荐文章于 2025-05-19 23:33:09 发布