File tree Expand file tree Collapse file tree 3 files changed +63
-0
lines changed Expand file tree Collapse file tree 3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ from typing import List
2
+
3
+
4
+ class Solution :
5
+ def threeSum (self , nums : List [int ]) -> List [List [int ]]:
6
+ answer = []
7
+ nums .sort ()
8
+ nums_len = len (nums )
9
+
10
+ for i in range (nums_len - 2 ):
11
+ if i > 0 and nums [i ] == nums [i - 1 ]:
12
+ continue
13
+ left , right = i + 1 , nums_len - 1
14
+
15
+ while left < right :
16
+ current_sum = nums [i ] + nums [left ] + nums [right ]
17
+ if current_sum < 0 :
18
+ left += 1
19
+ elif current_sum > 0 :
20
+ right -= 1
21
+
22
+ else :
23
+ answer .append ([nums [i ], nums [left ], nums [right ]])
24
+ while left < right and nums [left ] == nums [left + 1 ]:
25
+ left += 1
26
+ while left < right and nums [right ] == nums [right - 1 ]:
27
+ right -= 1
28
+ left += 1
29
+ right -= 1
30
+
31
+ return answer
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def climbStairs (self , n : int ) -> int :
3
+ if n <= 2 :
4
+ return n
5
+
6
+ dp = [0 ] * (n + 1 )
7
+ dp [1 ] = 1
8
+ dp [2 ] = 2
9
+
10
+ for i in range (3 , n + 1 ):
11
+ dp [i ] = dp [i - 1 ] + dp [i - 2 ]
12
+
13
+ return dp [n ]
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ # dictionary 사용 11ms
3
+ def isAnagram (self , s : str , t : str ) -> bool :
4
+ check = {}
5
+ for char in s :
6
+ if char not in check :
7
+ check [char ] = 0
8
+ check [char ] += 1
9
+ for char in t :
10
+ if char not in check :
11
+ return False
12
+ check [char ] -= 1
13
+ if check [char ] == 0 :
14
+ del check [char ]
15
+ return not check
16
+
17
+ # 정렬 사용 15 - 20ms
18
+ # def isAnagram(self, s: str, t: str) -> bool:
19
+ # return sorted(s) == sorted(t)
You can’t perform that action at this time.
0 commit comments