You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/0200-0299/0219.Contains Duplicate II/README_EN.md
+35-28
Original file line number
Diff line number
Diff line change
@@ -39,18 +39,28 @@
39
39
40
40
## Solutions
41
41
42
+
**Approach 1: Hash Table**
43
+
44
+
We use a hash table $d$ to store the nearest index of the number it has visited.
45
+
46
+
We traverse the array `nums`. For the current element $nums[i]$, if it exists in the hash table, and the difference between its index and the current index is no larger than $k$, then return `true`. Otherwise, we add the current element into the hash table.
47
+
48
+
After the traversal, return `false`.
49
+
50
+
The time complexity is $O(n)$ and the space complexity is $O(n)$. Here $n$ is the length of array `nums`.
0 commit comments