We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8514a0f commit 4bfee38Copy full SHA for 4bfee38
solutions/solution_0219/__init__.py
@@ -1,2 +1,8 @@
1
class Solution:
2
- def containsNearbyDuplicate(self, nums: list[int], k: int) -> bool: ...
+ def containsNearbyDuplicate(self, nums: list[int], k: int) -> bool:
3
+ seen: dict[int, int] = {}
4
+ for i, num in enumerate(nums):
5
+ if num in seen and i - seen[num] <= k:
6
+ return True
7
+ seen[num] = i
8
+ return False
0 commit comments