变态跳台阶
作者:互联网
题目描述
一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
1--1
1--2
3--4
4--8
题解一:
public class Solution {
public int JumpFloorII(int target) {
if(target <= 1){
return 1;
}else{
return 2*JumpFloorII(target-1);
}
}
}
题解二:
public class Solution {
public int JumpFloorII(int target) {
int a = 0,b =1;
if(target == 1)
return 1;
for(int i = 2; i <= target;i++){
a = 2*b;
b = a;
}
return a;
}
}
标签:JumpFloorII,台阶,target,int,题解,变态,跳上,public 来源: https://blog.csdn.net/weixin_43573534/article/details/102752704