Skip to content

Commit cca1872

Browse files
committed
contains-duplicate sol (py)
1 parent 24a2c2d commit cca1872

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

contains-duplicate/hi-rachel.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
https://leetcode.com/problems/contains-duplicate/
3+
4+
Given an integer array nums,
5+
return true if any value appears at least twice in the array,
6+
and return false if every element is distinct.
7+
8+
TC: O(n)
9+
SC: O(n)
10+
"""
11+
12+
from typing import List
13+
14+
class Solution:
15+
def containsDuplicate(self, nums: List[int]) -> bool:
16+
seen = set()
17+
18+
for num in nums:
19+
if num in seen:
20+
return True
21+
else:
22+
seen.add(num)
23+
return False
24+
25+
26+
class Solution:
27+
def containsDuplicate(self, nums: List[int]) -> bool:
28+
return len(set(nums)) != len(nums)

0 commit comments

Comments
 (0)