- 一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果)。
- 斐波那契数列
- C++ 代码
public class Solution {
public int JumpFloor(int target) {
int pre = 0;
int cur = 1;
for(int i = 1; i<=target; i++) {
int tmp = cur;
cur += pre;
pre = tmp;
}
return cur;
}
}
网友评论