diff --git a/combination-sum/mandel-17.py b/combination-sum/mandel-17.py new file mode 100644 index 0000000000..7fd2261635 --- /dev/null +++ b/combination-sum/mandel-17.py @@ -0,0 +1,19 @@ +from typing import List + +class Solution: + def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: + result = [] + + def dfs(csum, index, path): + if csum < 0: + return + if csum == 0: + result.append(path) + return + + for i in range(index, len(candidates)): + dfs(csum - candidates[i], i, path + [candidates[i]]) + + dfs(target, 0, []) + return result + diff --git a/number-of-1-bits/mandel-17.py b/number-of-1-bits/mandel-17.py new file mode 100644 index 0000000000..2430138e22 --- /dev/null +++ b/number-of-1-bits/mandel-17.py @@ -0,0 +1,10 @@ +import collections + +class Solution: + def hammingWeight(self, n: int) -> int: + two_digit = [] + while n >= 1: + two_digit.append(n % 2) + n = n // 2 + cnt_dict = collections.Counter(two_digit) + return cnt_dict[1] diff --git a/valid-palindrome/mandel-17.py b/valid-palindrome/mandel-17.py new file mode 100644 index 0000000000..cf9eb0fdd3 --- /dev/null +++ b/valid-palindrome/mandel-17.py @@ -0,0 +1,4 @@ +class Solution: + def isPalindrome(self, s: str) -> bool: + ch = [c.lower() for c in s if c.isalnum()] + return ch == ch[::-1]