Skip to content

Commit 0a7f3a0

Browse files
week 2: climbing stairs
1 parent 2a70101 commit 0a7f3a0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

climbing-stairs/prograsshopper.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def climbStairs(self, n: int) -> int:
3+
'''
4+
sol 1
5+
Runtime: Beats 100.00% / O(n^2)
6+
Memory: Beats 8.16% / O(1)
7+
'''
8+
import math
9+
ways = 1
10+
max_count_2steps = int(n/2)
11+
for i in range(1, max_count_2steps+1):
12+
current = math.perm(n - i) / (math.perm(i) * math.perm(n-(2*i)))
13+
ways += current
14+
return int(ways)
15+
16+
'''
17+
sol 2
18+
Runtime: Beats 100.00% / O(n^2)
19+
Memory: Beats 48.54% / O(1)
20+
'''
21+
ways = 0
22+
max_count_2steps = n // 2
23+
for i in range(max_count_2steps + 1):
24+
ways += math.comb(n - i, i)
25+
return ways

0 commit comments

Comments
 (0)