Skip to content

Commit 38d4c3c

Browse files
committed
Week 03 soultions
1 parent 3229bea commit 38d4c3c

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

combination-sum/HYUNAHKO.py'

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
3+
result = []
4+
5+
def backtrack(start_idx, current_combination, current_sum):
6+
if current_sum == target:
7+
result.append(current_combination[:])
8+
return
9+
if current_sum > target:
10+
return
11+
12+
# 모든 후보 탐색
13+
for i in range(start_idx, len(candidates)):
14+
# 현재 숫자 선택
15+
current_combination.append(candidates[i])
16+
17+
# 같은 숫자를 다시 사용할 수 있으므로 i부터 시작
18+
backtrack(i, current_combination, current_sum + candidates[i])
19+
20+
# 백트래킹
21+
current_combination.pop()
22+
23+
backtrack(0, [], 0)
24+
return result
25+

number-of-1-bits/HYUNAHKO.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def hammingWeight(self, n: int) -> int:
3+
result = 1
4+
while (n//2 != 0):
5+
remainder = n % 2
6+
if (remainder==1):
7+
result+=1
8+
n = n//2
9+
return result
10+

product-of-array-except-self/HYUNAHKO.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ def productExceptSelf(self, nums: List[int]) -> List[int]:
3737

3838

3939
return result_list
40+
4041

valid-palindrome/HYUNAHKO.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def isPalindrome(self, s: str) -> bool:
3+
s = s.lower()
4+
result = [char for char in s if char.isalnum()]
5+
6+
n = len(result)
7+
for i in range(n):
8+
str1 = result[i]
9+
if (str1 != result[n-i-1]):
10+
return False
11+
return True
12+

0 commit comments

Comments
 (0)