Skip to content

Commit 1f77046

Browse files
authored
Merge pull request #2088 from daiyongg-kim/main
[daiyongg-kim] WEEK 03 solutions
2 parents 1a53cf1 + 7eb92a6 commit 1f77046

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

combination-sum/daiyongg-kim.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution:
2+
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
3+
candidates.sort()
4+
result = []
5+
6+
def backtracking(start_index, current_combination, current_sum):
7+
if current_sum == target:
8+
result.append(list(current_combination))
9+
return
10+
11+
if current_sum > target:
12+
return
13+
14+
for i in range(start_index, len(candidates)):
15+
candidate = candidates[i]
16+
17+
if current_sum + candidate > target:
18+
break
19+
20+
current_combination.append(candidate)
21+
backtracking(i, current_combination, current_sum + candidate)
22+
23+
current_combination.pop()
24+
25+
backtracking(0, [], 0)
26+
return result

decode-ways/daiyongg-kim.py

Whitespace-only changes.

maximum-subarray/daiyongg-kim.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def maxSubArray(self, nums: List[int]) -> int:
3+
current_sum = nums[0]
4+
max_sum = nums[0]
5+
6+
for i in range(1, len(nums)):
7+
current_sum = max(nums[i], current_sum + nums[i])
8+
max_sum = max(current_sum, max_sum)
9+
10+
return max_sum

number-of-1-bits/daiyongg-kim.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+
cnt = 0
4+
5+
while n != 0:
6+
if n & 1:
7+
cnt += 1
8+
n = n >> 1
9+
10+
return cnt

valid-palindrome/daiyongg-kim.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Solution:
2+
def isPalindrome(self, s: str) -> bool:
3+
s = re.sub(r'[^0-9A-Za-z]', '',s).lower()
4+
return s == s[::-1]

0 commit comments

Comments
 (0)