MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / containsNearbyDuplicate

Method containsNearbyDuplicate

python/0219-contains-duplicate-ii.py:2–13  ·  view source on GitHub ↗
(self, nums: List[int], k: int)

Source from the content-addressed store, hash-verified

1class 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

Callers

nothing calls this directly

Calls 2

removeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected