We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2a70101 commit 0a7f3a0Copy full SHA for 0a7f3a0
climbing-stairs/prograsshopper.py
@@ -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
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