File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ # 시간 복잡도 : o(n)
2+ # 공간 복잡도 o(n)
3+
4+
5+ class Solution :
6+ def containsDuplicate (self , nums : List [int ]) -> bool :
7+ hashmap = {}
8+
9+ for i , n in enumerate (nums ):
10+ if n in hashmap :
11+ return True
12+ hashmap [n ] = i
13+ return False
14+
15+
16+ # -------------------------------------------------------------------------------------------------------- #
17+
18+ # 시간 복잡도 : o(n)
19+ # 공간 복잡도 o(n)
20+
21+
22+ class Solution :
23+ def containsDuplicate (self , nums : List [int ]) -> bool :
24+ seen = set ()
25+
26+ for n in nums :
27+ if n in seen :
28+ return True
29+ seen .add (n )
30+ return False
Original file line number Diff line number Diff line change 1+ # time complexity : o(n)
2+ # space complexity : o(n)
3+ class Solution :
4+ def twoSum (self , nums : List [int ], target : int ) -> List [int ]:
5+ hashmap = {}
6+
7+ for i , n in enumerate (nums ):
8+ diff = target - n
9+ if diff in hashmap :
10+ return [i , hashmap [diff ]]
11+ else :
12+ hashmap [n ] = i
You can’t perform that action at this time.
0 commit comments