Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions combination-sum/iam-edwin.py
Original file line number Diff line number Diff line change
@@ -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]
4 changes: 4 additions & 0 deletions number-of-1-bits/iam-edwin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Solution:
def hammingWeight(self, n: int) -> int:
binaryString = bin(n)[2:]
return list(binaryString).count("1")
20 changes: 20 additions & 0 deletions valid-palindrome/iam-edwin.py
Original file line number Diff line number Diff line change
@@ -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