diff --git a/combination-sum/8804who.py b/combination-sum/8804who.py new file mode 100644 index 0000000000..614ca0949c --- /dev/null +++ b/combination-sum/8804who.py @@ -0,0 +1,22 @@ +class Solution: + def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: + dp = {} + + for i in range(target+1): + dp[i] = set() + + for candidate in candidates: + if candidate <= target: + dp[candidate].add(tuple([candidate])) + + for i in range(target+1): + for candidate in candidates: + if i-candidate >= 0: + for j in dp[i-candidate]: + arr = [nums for nums in j]+[candidate] + arr.sort() + dp[i].add(tuple(arr)) + + answer = [list(nums) for nums in dp[target]] + return answer + diff --git a/decode-ways/8804who.py b/decode-ways/8804who.py new file mode 100644 index 0000000000..eda559752c --- /dev/null +++ b/decode-ways/8804who.py @@ -0,0 +1,23 @@ +class Solution: + def numDecodings(self, s: str) -> int: + dp = [0]*(len(s)+1) + s = '0'+s + dp[0] = 1 + for i in range(1, len(s)): + if int(s[i]) == 0: + if int(s[i-1]) != 1 and int(s[i-1]) != 2: + return 0 + else: + dp[i]=dp[i-2] + elif int(s[i]) <= 6: + if int(s[i-1]) != 1 and int(s[i-1]) != 2: + dp[i]=dp[i-1] + else: + dp[i]=dp[i-1]+dp[i-2] + else: + if int(s[i-1]) == 1: + dp[i]=dp[i-1]+dp[i-2] + else: + dp[i]=dp[i-1] + return dp[-1] + diff --git a/maximum-subarray/8804who.py b/maximum-subarray/8804who.py new file mode 100644 index 0000000000..74dfad453c --- /dev/null +++ b/maximum-subarray/8804who.py @@ -0,0 +1,14 @@ +class Solution: + def maxSubArray(self, nums: List[int]) -> int: + s = 0 + min_s = 0 + max_s = nums[0] + + for num in nums: + s += num + if max_s < s-min_s: + max_s=s-min_s + if min_s > s: + min_s = s + return max_s + diff --git a/number-of-1-bits/8804who.py b/number-of-1-bits/8804who.py new file mode 100644 index 0000000000..293c39aba1 --- /dev/null +++ b/number-of-1-bits/8804who.py @@ -0,0 +1,5 @@ +class Solution: + hammingWeight = lambda _, n: n.bit_count() + + + diff --git a/valid-palindrome/8804who.py b/valid-palindrome/8804who.py new file mode 100644 index 0000000000..6142d92129 --- /dev/null +++ b/valid-palindrome/8804who.py @@ -0,0 +1,6 @@ +import re +class Solution: + def isPalindrome(self, s: str) -> bool: + parsed_string = re.sub('[^a-zA-Z0-9]','',s).upper() + return parsed_string == parsed_string[::-1] +