diff --git a/.plan b/.plan index eca8072..4ac2d46 100644 --- a/.plan +++ b/.plan @@ -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" @@ -20,5 +24,4 @@ Sep 2, 2024 Sep 1, 2024 complete top interview 150 - * solve "205. Isomorphic Strings" diff --git a/src/contains_duplicate_ii.py b/src/contains_duplicate_ii.py index cea1e93..8b55691 100644 --- a/src/contains_duplicate_ii.py +++ b/src/contains_duplicate_ii.py @@ -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