2021.10.09 - JZ10.II.青蛙跳台阶问题
作者:互联网
文章目录
1. 题目
2. 思路
(1) 迭代
- 斐波那契数列的应用,修改初始条件即可。
3. 代码
public class Test {
public static void main(String[] args) {
}
}
class Solution {
public int numWays(int n) {
if (n < 2) {
return 1;
}
int n1 = 1;
int n2 = 1;
int res = 2;
while (n > 2) {
n1 = n2;
n2 = res;
res = (n1 + n2) % 1000000007;
n--;
}
return res;
}
}
标签:JZ10,return,2021.10,int,res,09,n1,n2,public 来源: https://blog.csdn.net/qq_44021223/article/details/120676926