package common;
/**
* @author : zhaoliang
* @program :newCoder
* @description : 跳台阶
* @create : 2020/11/21 14:25
*/
public class JumpFloor {
//斐波那契数列换种说法
public static int jumpFloor(int n){
if (n<=0)return 0;
if (n<=2)return n;
int first = 1,second =1,third=2;
for (int i = 3; i <=n; i++) {
third = first+second;
first = second;
second = third;
}
return third;
}
}
常见算法-跳台阶
最新推荐文章于 2021-09-04 20:03:56 发布