Skip to content

Commit 4bfee38

Browse files
committed
solution: 0219. Contains Duplicate II
1 parent 8514a0f commit 4bfee38

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

solutions/solution_0219/__init__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
class Solution:
2-
def containsNearbyDuplicate(self, nums: list[int], k: int) -> bool: ...
2+
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

Comments
 (0)