File tree Expand file tree Collapse file tree 5 files changed +66
-0
lines changed Expand file tree Collapse file tree 5 files changed +66
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ 시간 복잡도: O(target * n)
3
+ 공간 복잡도: O(n)?
4
+ 개인적으로 어려웠던 문제라서 정답을 봤습니다.
5
+ 추후에 다시 복습할 예정입니다.
6
+ """
7
+ class Solution :
8
+ def combinationSum (self , candidates : List [int ], target : int ) -> List [List [int ]]:
9
+ dp = [[] for _ in range (target + 1 )]
10
+ dp [0 ] = [[]]
11
+ for candidate in candidates :
12
+ for num in range (candidate , target + 1 ):
13
+ for combination in dp [num - candidate ]:
14
+ dp [num ].append (combination + [candidate ])
15
+ return dp [target ]
Original file line number Diff line number Diff line change
1
+ """
2
+ 시간 복잡도: O(N)
3
+ 공간 복잡도: O(N)
4
+ """
5
+ class Solution :
6
+ def numDecodings (self , s : str ) -> int :
7
+ dp = [0 ] * len (s ) + [1 ]
8
+
9
+ for i in reversed (range (len (s ))):
10
+ if s [i ] == "0" :
11
+ dp [i ] = 0
12
+ elif i + 1 < len (s ) and int (s [i : i + 2 ]) < 27 :
13
+ dp [i ] = dp [i + 1 ] + dp [i + 2 ]
14
+ else :
15
+ dp [i ] = dp [i + 1 ]
16
+
17
+ return dp [0 ]
Original file line number Diff line number Diff line change
1
+ """
2
+ 시간 복잡도 O(N)
3
+ 공간 복잡도 O(N)
4
+ """
5
+ class Solution :
6
+ def maxSubArray (self , nums : List [int ]) -> int :
7
+ dp = [0 ] * len (nums )
8
+ dp [0 ] = nums [0 ]
9
+
10
+ for i in range (1 , len (nums )):
11
+ dp [i ] = max (nums [i ], dp [i - 1 ] + nums [i ])
12
+
13
+ return max (dp )
Original file line number Diff line number Diff line change
1
+ """
2
+ 시간 복잡도: O(logN)
3
+ 공간 복잡도: O(1)
4
+ """
5
+ class Solution :
6
+ def hammingWeight (self , n : int ) -> int :
7
+ result = 1
8
+ while n // 2 != 0 :
9
+ a = n // 2
10
+ b = n % 2
11
+ result += b
12
+ n = a
13
+ return result
Original file line number Diff line number Diff line change
1
+ """
2
+ 시간 복잡도: O(N)
3
+ 공간 복잡도: O(N)
4
+ """
5
+ class Solution :
6
+ def isPalindrome (self , s : str ) -> bool :
7
+ filterd_s = [ch for ch in s .lower () if ch .isalnum ()]
8
+ return filterd_s == filterd_s [::- 1 ]
You can’t perform that action at this time.
0 commit comments