跳台阶
题目描述:
一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
解题思路:
其实仔细分析一下,可以发现这是一个类似斐波那契数列的数组,数组为:0,1,2,3,5,8,…
下面是我的Java源代码实现:
public class Solution {
public int JumpFloor(int target) {
if(target==0 || target == 1 ){
return target;
}else{
int a = 1;
int b = 2;
int i = 2;
while(i<target){
b = a+b;
a = b-a;
i++;
}
return b;
}
}
}