File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments