/**
*一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
*/
public class Solution {
public int JumpFloor(int target) {
if(target<=2){
return target;
}
int start=1;
int end =2;
end=this.sum(start,end,3,target);
return end;
}
/**
*分析出数据: 1 2 3 5 8
*start 前一个台阶跳法
*end 当前台阶跳法
*total 总台阶
*/
public int sum(int start,int end ,int i ,int total){
if(i<=total){
int tmp=start;
start=end;
end+=tmp;
end=this.sum(start,end,i+1,total);
}
return end;
}
}
/**
*一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法
*/
/**
*数据分析1 2 4
*/
public class Solution {
public int JumpFloorII(int target) {
return 1<<(target-1);
}
}