File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed
Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution :
2+ def combinationSum (self , candidates : List [int ], target : int ) -> List [List [int ]]:
3+ """
4+ - ์๊ฐ๋ณต์ก๋: O(n^2)
5+ - ๊ณต๊ฐ๋ณต์ก๋: O(n)
6+ DFS ์ฌ์ฉ
7+ 1. ๋ชจ๋ ์กฐํฉ์ ์ฐพ๊ธฐ
8+ 2. ์กฐํฉ์ ์ฐพ์ ๋, ์ค๋ณต๋ ์กฐํฉ์ ๋ฐฉ์งํ๊ธฐ
9+ """
10+ result = []
11+
12+ def dfs (start , path , total ):
13+ if total == target :
14+ result .append (path [:])
15+ return
16+ if total > target :
17+ return
18+
19+ for i in range (start , len (candidates )):
20+ path .append (candidates [i ])
21+ dfs (i , path , total + candidates [i ])
22+ path .pop ()
23+
24+ dfs (0 , [], 0 )
25+ return result
Original file line number Diff line number Diff line change 1+ from collections import Counter
2+
3+ class Solution :
4+ def hammingWeight (self , n : int ) -> int :
5+ """
6+ - ์๊ฐ๋ณต์ก๋: O(n)
7+ - ๊ณต๊ฐ๋ณต์ก๋: O(n)
8+ ๋ฌธ์์ด์ ์ด์ง์๋ก ๋ณํํ๊ณ , 1์ ๊ฐ์๋ฅผ ์ธ๊ธฐ
9+ """
10+ return Counter (bin (n )[2 :])["1" ]
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def isPalindrome (self , s : str ) -> bool :
3+ """
4+ - ์๊ฐ๋ณต์ก๋: O(n)
5+ - ๊ณต๊ฐ๋ณต์ก๋: O(n)
6+ 1. ๋ฌธ์์ด์ ์๋ฌธ์๋ก ๋ณํํ๊ณ , ์ํ๋ฒณ๊ณผ ์ซ์๋ง ๋จ๊ธฐ๊ธฐ
7+ 2. ๋จ์ ๋ฌธ์์ด์ ์ ๋ฐ์ผ๋ก ๋๋๊ณ , ์๊ณผ ๋ค๋ฅผ ๋น๊ตํ์ฌ ํ๋ฌธ์ธ์ง ํ์ธ
8+ 3. ํ๋ฌธ์ด๋ฉด True, ์๋๋ฉด False ๋ฐํ
9+ """
10+ a = ""
11+ for i in s .lower ():
12+ if i .isalnum ():
13+ a += i
14+ for i , j in zip (a [:len (a ) // 2 ], a [len (a ):(len (a ) // 2 - 1 ):- 1 ]):
15+ if i != j :
16+ return False
17+ return True
You canโt perform that action at this time.
0 commit comments