70.爬楼梯(通过)Python
程序员文章站
2022-07-12 12:03:33
...
前9阶的解法分别是:1,2,3,5,8,13,21,34,55
由上可知,与Fibonacci sequence及其相似
class Solution:
def climbStairs(self, n):
"""
:type n: int
:rtype: int
"""
tmp = 1
res = 2
if n == 1:
return 1
elif n == 2:
return 2
else:
for i in range(2,n):
result = tmp + res
tmp = res
res = result
return result
上一篇: 递归:求x的y次幂
下一篇: Pow,求x的y次幂