剑指Offer--8.跳台阶
来源:互联网 发布:首都医科大学知乎 编辑:程序博客网 时间:2024/06/05 03:57
题目描述:
一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
python代码:
# -*- coding:utf-8 -*-class Solution: def jumpFloor(self, number): # write code here if number <= 0: return 0 a = 1 b = 1 for _ in xrange(number): b,a = a+b,b return a
解析:
可以用递归的思路,f(1)=1,f(2) = 2,f(n) = f(n-1) +f(n-2),就是先跳一个台阶的组合数加上先跳两个台阶的组合数。
同时,这个问题仍然是一个斐波那契数列,number = 1时 a=1,number=2时,a=2,number=3时,a = 1+2 ,........
阅读全文
0 0
- 剑指offer-8.跳台阶
- 剑指Offer--8.跳台阶
- [剑指Offer] 8.跳台阶
- 剑指offer-跳台阶
- 【剑指offer】跳台阶
- 剑指offer--跳台阶
- 《剑指offer》跳台阶
- 剑指Offer-跳台阶
- 《剑指offer》跳台阶
- 剑指 offer:跳台阶
- 【剑指Offer】跳台阶
- 剑指offer 跳台阶
- 剑指offer--跳台阶
- 剑指offer 跳台阶
- 《剑指offer》跳台阶
- 剑指offer-跳台阶
- 剑指offer----跳台阶
- 剑指Offer:跳台阶
- python邮件发送给多人时,只有第一个人能收到的问题
- jsonp协议原理深度解析
- Letter c语言-Combinations of a Phone Number
- UGUI-仿照NGUI的事件监听机制
- 使用线性分类模型从事良/恶性肿瘤预测任务
- 剑指Offer--8.跳台阶
- Eclipse配置tomcat
- ModelAndVIew——视图渲染器
- Qt Quick属性特性
- 前端开发工具、库和资源
- eclipse maven 项目 maven build 无反应
- 边权更新 查询路径长度和最大边权 【树链剖分 模板】
- java 虚拟机内存分配
- mac上键盘说明以及intellij 快捷键的使用