剑指 Offer 10- II. 青蛙跳台阶问题
题目
青蛙跳台阶问题
C++代码
class Solution {
public:
int numWays(int n){
if(n == 0)
return 1;
if(n == 1)
return 1;
if(n == 2)
return 2;
int a = 1, b = 2;
for(int i = 3; i <= n; i++){
int tmp = a + b;
a = b;
b = tmp % 1000000007;
}
return b % 1000000007;
}
};
Java代码
class Solution
共有 0 条评论