blob: 6c1f357109e590b5c6ffb4a6eea43389ac99e33a (
plain)
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
|
# 70. Climbing Stairs
"""
you are climbinga staircase. it takes 'n' steps to reach the top. each time
you can either climb one or two steps. in how many distinct ways can you
climb to the top?
"""
class Solution(object):
def climbStairs(self, n):
"""
:type n: int
:rtype: int
"""
ways = 1
for i in range(1, (n // 2) + 1):
product = 1
for j in range(i, 2 * i):
product *= (n - j) / (j - i + 1)
ways += product
return int(ways)
if __name__ == "__main__":
obj = Solution()
print(obj.climbStairs(2))
print(obj.climbStairs(3))
|