Skip to content

Commit f4ac433

Browse files
committed
add solution: contains duplicate
1 parent 8901b1d commit f4ac433

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

contains-duplicate/SunaDu.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'''
2+
# Leetcode 217. Contains Duplicate
3+
4+
use set to store distinct elements 🗂️
5+
6+
## Time and Space Complexity
7+
8+
```
9+
TC: O(n)
10+
SC: O(n)
11+
```
12+
13+
### TC is O(n):
14+
- iterating through the list just once to convert it to a set.
15+
16+
### SC is O(n):
17+
- creating a set to store the distinct elements of the list.
18+
'''
19+
20+
class Solution:
21+
def containsDuplicate(self, nums: List[int]) -> bool:
22+
return len(nums) != len(set(nums))

0 commit comments

Comments
 (0)