[LeetCode] 219. Contains Duplicate II
Python
class Solution:
def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:
if len(nums) == len(set(nums)):
return False
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
if nums[i] == nums[j]:
if abs(i - j) <= k:
return True
return False
댓글남기기