File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ # 공간복잡도 : O(1), 시간복잡도 : O(N^2)
2
+ class Solution :
3
+ def threeSum (self , nums : List [int ]) -> List [List [int ]]:
4
+ three_sums = set ()
5
+ nums .sort ()
6
+
7
+ for i in range (len (nums )- 2 ):
8
+ low , high = i + 1 , len (nums )- 1
9
+ while low < high :
10
+ three_sum = nums [i ] + nums [high ] + nums [low ]
11
+ if three_sum < 0 :
12
+ low += 1
13
+ elif three_sum > 0 :
14
+ high -= 1
15
+ else :
16
+ three_sums .add ((nums [i ], nums [high ], nums [low ]))
17
+ low , high = low + 1 , high - 1
18
+
19
+ return list (three_sums )
20
+
Original file line number Diff line number Diff line change
1
+ # 공간복잡도: O(1), 시간복잡도: O(n)
2
+ class Solution :
3
+ def climbStairs (self , n : int ) -> int :
4
+ if n < 3 :
5
+ return n
6
+
7
+ prev , curr = 1 , 2
8
+ for num in range (3 , n + 1 ):
9
+ prev , curr = curr , prev + curr
10
+
11
+ return curr
Original file line number Diff line number Diff line change
1
+ # 공간복잡도: O(n), 시간복잡도: O(n)
2
+ class Solution :
3
+ def isAnagram (self , s : str , t : str ) -> bool :
4
+ char_set_1 , char_set_2 = {}, {}
5
+
6
+ for ch in s :
7
+ char_set_1 [ch ] = 0 if ch not in char_set_1 else char_set_1 [ch ] + 1
8
+
9
+ for ch in t :
10
+ char_set_2 [ch ] = 0 if ch not in char_set_2 else char_set_2 [ch ] + 1
11
+
12
+ # dictionary의 모든 요소 종류와 개수가 일치해야 함
13
+ return char_set_1 == char_set_2
14
+
You can’t perform that action at this time.
0 commit comments