-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathEstherKim97.py
33 lines (26 loc) · 1.09 KB
/
EstherKim97.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution(object):
def climbStairs(self, n):
import math
# First attempt to this question.
# Get dividend and remainder of 2 steps & get all combinations & add one additional method for all 1 step combination
# But how to get all combinations? => permutation
# def climbStairs(self, n):
# # 2 steps
# two_steps = n // 2
# two_steps_remainder = n % 2
# total_steps = two_steps + two_steps_remainder
# total_permu = math.factorial(total_steps) // (math.factorial(two_steps) * math.factorial(two_steps_remainder))
# total_permu += 1
# return total_permu
# Second method - n = 2x+y
if n % 2 == 0:
max = n //2
else:
max = (n-1) // 2
total_methods = 0
for i in range(0, max+1):
y = n - (2 * i)
total_steps = i + y
total_permu = math.factorial(total_steps) // (math.factorial(i) * math.factorial(y))
total_methods += total_permu
return total_methods