【Lintcode】斐波纳契数列
来源:互联网 发布:h3c配置vlan多个端口 编辑:程序博客网 时间:2024/05/17 23:11
非递归算法
class Solution { /** * @param n: an integer * @return an integer f(n) */ public int fibonacci(int n) { // write your code here if ( n == 1 ) { return 0; } else if ( n == 2 || n == 3 ) { return 1; } int s1 = 1; int s2 = 1; int i = 4; int sum = 0; while (i <= n) { sum = s1 + s2; s1 = s2; s2 = sum; i++; } return sum; }}
递归算法超过时间限制
public int fibonacci(int n) { // write your code here int a=0; int b=1; if(n==1)return a; if(n==2)return b; if(n>2)return fibonacci(n-1)+fibonacci(n-2); return 0; }
0 0
- LintCode--斐波纳契数列
- 【Lintcode】斐波纳契数列
- 【Lintcode】斐波纳契数列
- LintCode【入门】斐波纳契数列
- lintcode-入门-斐波纳契数列
- LintCode(斐波纳契数列)!
- Lintcode斐波纳契数列
- 斐波纳契数列-LintCode
- LintCode-第366题 斐波纳契数列
- 【LintCode-366】斐波纳契数列 (Java实现)
- LintCode 查找斐波纳契数列中第 N 个数
- LintCode 第366题 斐波纳契数列 【枚举法】
- LintCode之斐波那契数列
- lintcode斐波那契数列
- (lintcode)第336题斐波那契数列
- Lintcode:斐波那契数列
- 【LintCode】查找斐波那契数列中的N个数
- lintcode爬楼梯(斐波那契数列)
- MYSQL for mac 卸载篇
- xml文件中特殊符号代替
- 一些不错的技术文章
- spring mvc + mybaties+ mysql搭建--2016版
- 一个网页通用的测试用例(转载他人)
- 【Lintcode】斐波纳契数列
- sscanf,sscanf_s及其相关用法
- codeforce 621 B. Wet Shark and Bishops
- 算法系列_基础01_O(nlogn)的理解
- 自定义控制器的转场动画(Push、Pop)
- Android事件分发
- Android学习笔记(31):滚动视图ScrollView
- Cookie/Session机制详解
- 欢迎使用CSDN-markdown编辑器