Skip to content

Commit 11add93

Browse files
authored
Merge pull request #2110 from mandel-17/main
[madel-17] WEEK 03 solutions
2 parents 41df393 + c538722 commit 11add93

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

combination-sum/mandel-17.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from typing import List
2+
3+
class Solution:
4+
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
5+
result = []
6+
7+
def dfs(csum, index, path):
8+
if csum < 0:
9+
return
10+
if csum == 0:
11+
result.append(path)
12+
return
13+
14+
for i in range(index, len(candidates)):
15+
dfs(csum - candidates[i], i, path + [candidates[i]])
16+
17+
dfs(target, 0, [])
18+
return result
19+

number-of-1-bits/mandel-17.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import collections
2+
3+
class Solution:
4+
def hammingWeight(self, n: int) -> int:
5+
two_digit = []
6+
while n >= 1:
7+
two_digit.append(n % 2)
8+
n = n // 2
9+
cnt_dict = collections.Counter(two_digit)
10+
return cnt_dict[1]

valid-palindrome/mandel-17.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+
ch = [c.lower() for c in s if c.isalnum()]
4+
return ch == ch[::-1]

0 commit comments

Comments
 (0)