剑指Offer [08] 跳台阶
来源:互联网 发布:php jquery ajax 编辑:程序博客网 时间:2024/04/29 12:41
跳台阶 : 一只青蛙一次可以跳上 1 级台阶,也可以跳上 2 级。求该青蛙跳上一个 n 级的台阶总共有多少种跳法。
思路:
f(n) = f(n-1)+ f(n-2) 即第 n 次的结果等于跳 1 阶 + 跳 2 阶的和
其实就是计算斐波拉契数列
package A08跳台阶;public class Solution { public int JumpFloor(int target) { if (target <=0) { return 0; } int a = 1; int b = 0; while(target-- >= 0){ a = a+b; b = a-b; } return b; } public static void main(String[] args) { Solution solution = new Solution(); System.out.println(solution.JumpFloor(4)); }}
阅读全文
0 0
- 剑指Offer [08] 跳台阶
- 剑指offer-跳台阶
- 【剑指offer】跳台阶
- 剑指offer--跳台阶
- 《剑指offer》跳台阶
- 剑指Offer-跳台阶
- 《剑指offer》跳台阶
- 剑指 offer:跳台阶
- 【剑指Offer】跳台阶
- 剑指offer 跳台阶
- 剑指offer--跳台阶
- 剑指offer 跳台阶
- 《剑指offer》跳台阶
- 剑指offer-跳台阶
- 剑指offer----跳台阶
- 剑指Offer:跳台阶
- 《剑指Offer》 跳台阶
- 剑指offer--跳台阶
- HPU 1190 確率
- ACM训练日记—8月21日
- D
- 深入学习js之浅谈原型
- hdu6155-Subsequence Count(线段树+矩阵+dp)
- 剑指Offer [08] 跳台阶
- 解释器模式与状态模式
- HPU有四个餐厅
- Ubuntu——多线程实现单词统计工具
- 知识点集锦
- jQuery整体框架
- ImportError: No module named setuptools
- 《图解TCP/IP》(二)之IP协议详解
- 阿里巴巴FastJson对数据的常用操作