File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 1+ '''Leetcode - https://leetcode.com/problems/contains-duplicate/'''
2+
3+ # Solution1
4+ def containsDuplicate (nums ):
5+ for i in range (len (nums )):
6+ for j in range (i + 1 ,len (nums )):
7+ if nums [i ] == nums [j ]:
8+ return True
9+ return False
10+
11+ # T:O(N^2)
12+ # S:O(1)
13+
14+
15+ # Solution2
16+ def containsDuplicate (nums ):
17+ hashset = set ()
18+
19+ for i in len (nums ):
20+ if nums [i ] in hashset :
21+ return True
22+ hashset .add (nums [i ])
23+ return False
24+
25+ # T: O(N)
26+ # S: O(N)
Original file line number Diff line number Diff line change @@ -5,4 +5,5 @@ Curated List of Blind 75 solutions in Python.
55
66- [x] [ Arrays] ( Arrays )
77 - [x] [ Two Sum] ( Arrays/001-twosum.py )
8- - [x] [ Best Time to Buy & Sell Stock] ( Arrays/121-Best-Time-To-Buy-and-Sell-Stock )
8+ - [x] [ Best Time to Buy & Sell Stock] ( Arrays/121-Best-Time-To-Buy-and-Sell-Stock )
9+ - [x] [ Contains Duplicate] ( Arrays/217-Contains-duplicate )
You can’t perform that action at this time.
0 commit comments