File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed
product-of-array-except-self Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 1+ from collections import Counter
2+ class Solution :
3+ def isAnagram (self , s : str , t : str ) -> bool :
4+ return Counter (s ) == Counter (t )
5+
You can’t perform that action at this time.
0 commit comments