diff --git a/combination-sum/iam-edwin.py b/combination-sum/iam-edwin.py new file mode 100644 index 000000000..6d8ef8b94 --- /dev/null +++ b/combination-sum/iam-edwin.py @@ -0,0 +1,20 @@ +from typing import List + + +class Solution: + def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: + result = [[[] for _ in range(target + 1)] for _ in range(len(candidates))] + + for index in range(len(candidates)): + num = candidates[index] + for subTarget in range(1, target + 1): + maxUseCount = subTarget // num + for useCount in range(0, maxUseCount + 1): + subSubTarget = subTarget - num * useCount + if subSubTarget == 0: + result[index][subTarget].append([num] * useCount) + else: + for item in result[index - 1][subSubTarget]: + result[index][subTarget].append(item + [num] * useCount) + + return result[len(candidates) - 1][target] diff --git a/number-of-1-bits/iam-edwin.py b/number-of-1-bits/iam-edwin.py new file mode 100644 index 000000000..78cf09236 --- /dev/null +++ b/number-of-1-bits/iam-edwin.py @@ -0,0 +1,4 @@ +class Solution: + def hammingWeight(self, n: int) -> int: + binaryString = bin(n)[2:] + return list(binaryString).count("1") diff --git a/valid-palindrome/iam-edwin.py b/valid-palindrome/iam-edwin.py new file mode 100644 index 000000000..62da4414b --- /dev/null +++ b/valid-palindrome/iam-edwin.py @@ -0,0 +1,20 @@ +class Solution: + def isPalindrome(self, s: str) -> bool: + left = 0 + right = len(s) - 1 + + while left < right: + while left < len(s) - 1 and not s[left].isalnum(): + left += 1 + while right > 0 and not s[right].isalnum(): + right -= 1 + + if left >= right: + return True + elif s[left].lower() != s[right].lower(): + return False + else: + left += 1 + right -= 1 + + return True