Skip to content

Commit 39ccfaa

Browse files
committed
Week 02: climbing-stairs solution
1 parent 56446fe commit 39ccfaa

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

climbing-stairs/mandel-17.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
def climbStairs(self, n: int) -> int:
3+
def factorial(n):
4+
result = 1
5+
for i in range(1, n+1):
6+
result *= i
7+
return result
8+
9+
def combination(n, r):
10+
top = factorial(n)
11+
bottom = factorial(n-r) * factorial(r)
12+
return top / bottom
13+
14+
share = n // 2
15+
total = 1
16+
for i in range(1, share + 1):
17+
combination_n = n - i
18+
combination_r = i
19+
20+
total += combination(combination_n, combination_r)
21+
22+
return int(total)
23+

0 commit comments

Comments
 (0)