Skip to content

Commit

Permalink
re-solve "219. Contains Duplicate II"
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelote committed Sep 8, 2024
1 parent 9347267 commit 0f0e3d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions .plan
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Sep 7, 2024
Sep 8, 2024

solve all hashmap questions in top-150
* re-solve "219. Contains Duplicate II"
* investigate better approach for 202 solution

investigate better approach for 202 solution
Sep 7, 2024

* solve "202. Happy Number"
* re-solve "1. Two Sum"
Expand All @@ -20,5 +24,4 @@ Sep 2, 2024
Sep 1, 2024

complete top interview 150

* solve "205. Isomorphic Strings"
2 changes: 1 addition & 1 deletion src/contains_duplicate_ii.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def containsNearbyDuplicate(self, nums: list[int], k: int) -> bool:
cache: dict[int, int] = {}

for i, num in enumerate(nums):
if num in cache and abs(cache[num] - i) <= k:
if num in cache and i - cache[num] <= k:
return True
cache[num] = i

Expand Down

0 comments on commit 0f0e3d9

Please sign in to comment.