Skip to content

Commit 702eb2d

Browse files
committed
contains-duplicate
1 parent 53ce7c7 commit 702eb2d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

contains-duplicate/bskkimm.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from collections import defaultdict
2+
class Solution(object):
3+
def containsDuplicate(self, nums):
4+
"""
5+
:type nums: List[int]
6+
:rtype: bool
7+
"""
8+
# [1,2,3,1]
9+
10+
# [1,1,1,3,3,4,3,2,4,2]
11+
12+
# add element to a dict
13+
# if a same value appears, then return True
14+
# if a for loop ends without disruption, return False
15+
16+
dict = defaultdict(bool)
17+
18+
for num in nums:
19+
if dict[num]:
20+
return True
21+
else:
22+
dict[num] = True
23+
24+
return False

0 commit comments

Comments
 (0)