-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ70.py
More file actions
29 lines (26 loc) · 765 Bytes
/
Q70.py
File metadata and controls
29 lines (26 loc) · 765 Bytes
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
import math
class Solution:
def climbStairs(self, n: int) -> int:
#solution 1:
# if n<=2:
# return n
# return self.climbStairs(n-1)+self.climbStairs(n-2)
#solution2:
if n<=2:
return n
result = 1
for i in range(1,n//2+1):
result+=math.factorial(n-i*2+i)//(math.factorial(n-i*2)*math.factorial(i))
return result
#solution 3:
# """
# :type n: int
# :rtype: int
# """
# steps = [1,1]
# if n>=2:
# for i in range(2,n+1):
# steps.append(steps[i-1] + steps[i-2])
# return steps[-1]
if __name__ == '__main__':
print(Solution().climbStairs(3))