首页 > 其他 > 详细

jz008

时间:2021-05-24 15:28:08      阅读:17      评论:0      收藏:0      [点我收藏+]
//一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
分析:最后一次跳1有f(n-1)跳法,最后一跳2有f(n-2)跳法,f(n)=f(n-1)+f(n-2)
public class test {
public static void main(String[] args) {
int i = test(5);
System.out.println(i);
}
public static int test(int n){
if (n<=3){
return n;
}
int i =3;
int res=0;
int start;
int end;
start=2;
end =3;
while (i<n){
res =start+end;
i++;
start=end;
end =res;
}
return res;
}
}

jz008

原文:https://www.cnblogs.com/rxqdsg/p/14803112.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!