Skip to content

Commit a91888e

Browse files
authored
Create 0219-contains-duplicate-ii.py
1 parent 0a937c5 commit a91888e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

python/0219-contains-duplicate-ii.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:
3+
window = set()
4+
L = 0
5+
6+
for R in range(len(nums)):
7+
if R - L > k:
8+
window.remove(nums[L])
9+
L += 1
10+
if nums[R] in window:
11+
return True
12+
window.add(nums[R])
13+
return False

0 commit comments

Comments
 (0)