diff --git a/climbing-stairs/mangodm-web.py b/climbing-stairs/mangodm-web.py new file mode 100644 index 000000000..97046de45 --- /dev/null +++ b/climbing-stairs/mangodm-web.py @@ -0,0 +1,9 @@ +class Solution: + def climbStairs(self, n: int) -> int: + dp = [0] * (n + 1) + dp[0], dp[1] = 1, 1 + + for i in range(2, n + 1): + dp[i] = dp[i - 1] + dp[i - 2] + + return dp[n] diff --git a/product-of-array-except-self/mangodm-web.py b/product-of-array-except-self/mangodm-web.py new file mode 100644 index 000000000..3da15467b --- /dev/null +++ b/product-of-array-except-self/mangodm-web.py @@ -0,0 +1,19 @@ +from typing import List + + +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + result = [] + + product = 1 + for i in range(len(nums)): + result.append(product) + product *= nums[i] + + product = 1 + + for i in range(len(nums) - 1, -1, -1): + result[i] *= product + product *= nums[i] + + return result diff --git a/two-sum/mangodm-web.py b/two-sum/mangodm-web.py new file mode 100644 index 000000000..8cb5f696e --- /dev/null +++ b/two-sum/mangodm-web.py @@ -0,0 +1,13 @@ +from typing import List + + +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + index_map = {} + + for i, n in enumerate(nums): + complement = target - n + + if complement in index_map: + return [index_map[complement], i] + index_map[n] = i