Skip to content

Commit b05f8bb

Browse files
committed
Week 2
1 parent 2eb3c90 commit b05f8bb

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

climbing-stairs/8804who.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def climbStairs(self, n: int) -> int:
3+
dp = [1] * (n+1)
4+
5+
for i in range(2, n+1):
6+
dp[i] = dp[i-1]+dp[i-2]
7+
8+
return dp[n]
9+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def productExceptSelf(self, nums: List[int]) -> List[int]:
3+
total_product = 1
4+
5+
for num in nums:
6+
if num != 0:
7+
total_product *= num
8+
9+
if nums.count(0) == 1:
10+
return [0 if num != 0 else total_product for num in nums]
11+
elif nums.count(0) > 1:
12+
return [0 for _ in range(len(nums))]
13+
else:
14+
return [total_product//num for num in nums]
15+
16+
17+

valid-anagram/8804who.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from collections import Counter
2+
class Solution:
3+
def isAnagram(self, s: str, t: str) -> bool:
4+
return Counter(s) == Counter(t)
5+

0 commit comments

Comments
 (0)