您的位置:首页 > Web前端

剑指offer 8 跳台阶

2016-03-29 09:02 423 查看


题目描述

一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。

思路

和斐波那契数列一样的思路,f(n)=f(n-1)+f(n-2)。

public class Solution {
public int JumpFloor(int target) {
if(target==0)return 0;
//else if(target==1)return 1;
int a,b,c;
a=0;
b=1;
c=0;
while(target>0){
c=a+b;
a=b;
b=c;
target--;
}
return c;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: