Skip to content

Commit

Permalink
Merge pull request #403 from mangodm-web/main
Browse files Browse the repository at this point in the history
[mangodm-web] Week 03 Solutions
  • Loading branch information
leokim0922 authored Sep 3, 2024
2 parents 1c502dd + 75939e5 commit 0266b08
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
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

0 comments on commit 0266b08

Please sign in to comment.