Skip to content

[mangodm-web] Week 03 Solutions #403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 3, 2024
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
9 changes: 9 additions & 0 deletions climbing-stairs/mangodm-web.py
Original file line number Diff line number Diff line change
@@ -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]
19 changes: 19 additions & 0 deletions product-of-array-except-self/mangodm-web.py
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions two-sum/mangodm-web.py
Original file line number Diff line number Diff line change
@@ -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