剑指Offer----跳台阶
来源:互联网 发布:angularjs.js 2.0下载 编辑:程序博客网 时间:2024/06/04 18:25
一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
解题思路:1.斐波那契数列
public class Solution { public int JumpFloor(int target) { if(target==1)return 1; if(target==2)return 2; return JumpFloor(target-1)+JumpFloor(target-2); }}2.依次类推
public class Solution { public int JumpFloor(int target) { if(target==0)return 0; if(target==1)return 1; if(target==2)return 2; int One=1; int Two=2; int N=0; for(int i=3;i<=target;i++){ N=One+Two; One=Two; Two=N; } return N; }}
阅读全文
0 0
- 剑指offer-跳台阶
- 【剑指offer】跳台阶
- 剑指offer--跳台阶
- 《剑指offer》跳台阶
- 剑指Offer-跳台阶
- 《剑指offer》跳台阶
- 剑指 offer:跳台阶
- 【剑指Offer】跳台阶
- 剑指offer 跳台阶
- 剑指offer--跳台阶
- 剑指offer 跳台阶
- 《剑指offer》跳台阶
- 剑指offer-跳台阶
- 剑指offer----跳台阶
- 剑指Offer:跳台阶
- 《剑指Offer》 跳台阶
- 剑指offer--跳台阶
- [剑指offer] 跳台阶
- 求最长上升子序列
- 【分析】Ceph系统架构
- “盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛
- 关于表达式中除数为0的容错机制的处理
- 把数组排成最小的数
- 剑指Offer----跳台阶
- Js-web-API(一)
- 实现自定义标签
- poll服务器
- 面向对象(上)
- leetcode 72. Edit Distance
- 20170710Windows11_2_事件内核对象
- 洛谷 P2023 [AHOI2009]维护序列(bzoj P1798 [Ahoi2009]Seq 维护序列seq)
- 链表