Skip to content

Commit fc94ed7

Browse files
committed
code for climbing stairs
1 parent 8ce8f25 commit fc94ed7

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

climbing-stairs/EstherKim97.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class Solution(object):
2+
def climbStairs(self, n):
3+
4+
import math
5+
6+
# Second method - n = 2x+y
7+
if n % 2 == 0:
8+
max = n //2
9+
else:
10+
max = (n-1) // 2
11+
12+
total_methods = 0
13+
14+
for i in range(0, max+1):
15+
y = n - (2 * i)
16+
total_steps = i + y
17+
18+
total_permu = math.factorial(total_steps) // (math.factorial(i) * math.factorial(y))
19+
total_methods += total_permu
20+
21+
return total_methods
22+
23+
24+
# First attempt to this question.
25+
# Get dividend and remainder of 2 steps & get all combinations & add one additional method for all 1 step combination
26+
# But how to get all combinations? => permutation
27+
# def climbStairs(self, n):
28+
# # 2 steps
29+
# two_steps = n // 2
30+
# two_steps_remainder = n % 2
31+
32+
# total_steps = two_steps + two_steps_remainder
33+
34+
# total_permu = math.factorial(total_steps) // (math.factorial(two_steps) * math.factorial(two_steps_remainder))
35+
# total_permu += 1
36+
37+
# return total_permu

0 commit comments

Comments
 (0)