Skip to content

Commit 0b0d971

Browse files
committed
Sync LeetCode submission Runtime - 11 ms (53.86%), Memory - 31.5 MB (42.56%)
1 parent 23c3da6 commit 0b0d971

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

0217-contains-duplicate/README.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,37 @@
22

33
<p>&nbsp;</p>
44
<p><strong class="example">Example 1:</strong></p>
5-
<pre><strong>Input:</strong> nums = [1,2,3,1]
6-
<strong>Output:</strong> true
7-
</pre><p><strong class="example">Example 2:</strong></p>
8-
<pre><strong>Input:</strong> nums = [1,2,3,4]
9-
<strong>Output:</strong> false
10-
</pre><p><strong class="example">Example 3:</strong></p>
11-
<pre><strong>Input:</strong> nums = [1,1,1,3,3,4,3,2,4,2]
12-
<strong>Output:</strong> true
13-
</pre>
5+
6+
<div class="example-block">
7+
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,1]</span></p>
8+
9+
<p><strong>Output:</strong> <span class="example-io">true</span></p>
10+
11+
<p><strong>Explanation:</strong></p>
12+
13+
<p>The element 1 occurs at the indices 0 and 3.</p>
14+
</div>
15+
16+
<p><strong class="example">Example 2:</strong></p>
17+
18+
<div class="example-block">
19+
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4]</span></p>
20+
21+
<p><strong>Output:</strong> <span class="example-io">false</span></p>
22+
23+
<p><strong>Explanation:</strong></p>
24+
25+
<p>All elements are distinct.</p>
26+
</div>
27+
28+
<p><strong class="example">Example 3:</strong></p>
29+
30+
<div class="example-block">
31+
<p><strong>Input:</strong> <span class="example-io">nums = [1,1,1,3,3,4,3,2,4,2]</span></p>
32+
33+
<p><strong>Output:</strong> <span class="example-io">true</span></p>
34+
</div>
35+
1436
<p>&nbsp;</p>
1537
<p><strong>Constraints:</strong></p>
1638

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
# Approach 3: Hash Set
2+
3+
# Time: O(n)
4+
# Space: O(n)
5+
16
class Solution:
27
def containsDuplicate(self, nums: List[int]) -> bool:
38
visited = set()
4-
9+
510
for num in nums:
611
if num in visited:
712
return True
8-
else:
9-
visited.add(num)
13+
visited.add(num)
14+
1015
return False
16+

0 commit comments

Comments
 (0)