Skip to content

Commit 0266b08

Browse files
authored
Merge pull request #403 from mangodm-web/main
[mangodm-web] Week 03 Solutions
2 parents 1c502dd + 75939e5 commit 0266b08

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

climbing-stairs/mangodm-web.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def climbStairs(self, n: int) -> int:
3+
dp = [0] * (n + 1)
4+
dp[0], dp[1] = 1, 1
5+
6+
for i in range(2, n + 1):
7+
dp[i] = dp[i - 1] + dp[i - 2]
8+
9+
return dp[n]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def productExceptSelf(self, nums: List[int]) -> List[int]:
6+
result = []
7+
8+
product = 1
9+
for i in range(len(nums)):
10+
result.append(product)
11+
product *= nums[i]
12+
13+
product = 1
14+
15+
for i in range(len(nums) - 1, -1, -1):
16+
result[i] *= product
17+
product *= nums[i]
18+
19+
return result

two-sum/mangodm-web.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def twoSum(self, nums: List[int], target: int) -> List[int]:
6+
index_map = {}
7+
8+
for i, n in enumerate(nums):
9+
complement = target - n
10+
11+
if complement in index_map:
12+
return [index_map[complement], i]
13+
index_map[n] = i

0 commit comments

Comments
 (0)