[剑指offer]算法7 斐波那契数列
来源:互联网 发布:手机怎么避开网络监控 编辑:程序博客网 时间:2024/06/01 08:32
题目描述
大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项。n<=39
时间限制:1秒空间限制:32768K
分析:斐波那契数列就是下一个数是前面两数的和,所以没有什么很复杂的解过程。
【JAVA代码】
public class Solution { public int Fibonacci(int n) { int sum = 0,temp=0; int nextNum=1; for(int i=0;i<n;i++){ sum=temp+nextNum; nextNum=temp; temp=sum; } return sum;
package Offer;public class DigUI {public static void main(String[] args) {DigUI d = new DigUI();System.out.println(d.f(5));}public int f(int n) {if(n<=1) return 1;else {return f(n-1)+f(n-2);}}}递归实现
阅读全文
0 0
- [剑指offer]算法7 斐波那契数列
- 【剑指offer】斐波那契数列
- 剑指offer--斐波那契数列
- 剑指Offer-斐波那契数列
- 剑指offer:斐波那契数列
- 《剑指offer》斐波那契数列
- 剑指 offer:斐波那契数列
- 【剑指Offer】斐波那契数列
- 剑指offer 斐波那契数列
- 【剑指offer】斐波那契数列
- 剑指offer 斐波那契数列
- [剑指offer]斐波那契数列
- 剑指offer|斐波那契数列
- 【剑指offer】斐波那契数列
- 剑指offer--斐波那契数列
- 剑指Offer:斐波那契数列
- 《剑指Offer》斐波那契数列
- 剑指offer----斐波那契数列
- FLYPRO飞豹携XEagle无人机 亮相2016全球最大无人机展AUVSI XPONENTIAL
- 细菌也能制造量子点,敢情又要换电视了?
- 把最美献给母亲节 OPPO R9记录世界微笑日
- UVALive
- Thread
- [剑指offer]算法7 斐波那契数列
- android studio3.0使用报错解决
- 常用的机器学习算法学习
- freemarker模板引擎
- 移动开发调试模式
- 链表 二叉树
- 继下架全部医院广告之后 360搜索发布首份医疗机构白名单
- Halcon联合VS2010打开相机并显示
- Linux下Zookeeper自启动