Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 167e713

Browse files
committed
Add comments for problem 0219
1 parent fe46566 commit 167e713

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

‎solution/0219.Contains Duplicate II/Solution.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33
44
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k.
55
'''
6+
# Performance
67
'''
78
Runtime: 96 ms, faster than 93.53% of Python3 online submissions for Contains Duplicate II.
89
Memory Usage: 20.5 MB, less than 62.50% of Python3 online submissions for Contains Duplicate II.
910
'''
1011

11-
# Create a hashmap to remember the most recent position of unique values
12-
# If we found duplicate and the range is less than k, then return true
13-
# Else remember that index
12+
# Algorithm Explained
13+
'''
14+
Create a hashmap to remember the most recent position of unique values
15+
If we found duplicate and the range is less than k, then return true
16+
Else remember that index
17+
18+
Space: O(n) with n is the number of original array
19+
Complexity: O(n)
20+
'''
1421
class Solution:
1522
def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:
1623
pos = {}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /