class Solution:
def climbStairs(self, n):
"""
:type n: int
:rtype: int
"""
##递归超时
# if n==1:
# s=1
# if n==2:
# s=2
# if(n>2):
# s=self.climbStairs(n-1)+self.climbStairs(n-2)
# return s
a=0
b=1
for i in range(n):
a,b=b,a+b
return b
pythonLeetCode70:爬楼梯(斐波那契)
最新推荐文章于 2022-05-27 19:42:56 发布