剑指Offer 10- II. 青蛙跳台阶问题(Easy)
【题目链接】
题解
青蛙跳台阶问题(动态规划,清晰图解)
方法
class Solution(object):
def numWays(self
, n
):
"""
:type n: int
:rtype: int
"""
record
= {}
record
[0], record
[1] = 1, 1
for i
in range(2, n
+1):
record
[i
] = (record
[i
-1] + record
[i
-2]) % (1e9+7)
return int(record
[n
])
def numWays(self
, n
):
a
, b
= 1, 1
for _
in range(n
):
a
, b
= b
, a
+ b
return a
% 1000000007
转载请注明原文地址:https://tech.qufami.com/read-26936.html