2016.12.4, 366

http://www.lintcode.com/en/problem/fibonacci/

一刷使用递归算法,超时。二刷使用九章算术的算法,就是滚动指针的思路,以前写python的时候也玩过,但是给忘了,这次又用c++拾起来了。lint有bug,不能用,很烦。

class Solution {
public:
/**
* @param n: an integer
* @return an integer f(n)
*/
int fibonacci(int n) {
int a = , b = ;
for (int i = ; i < n; i++) {
int c = a + b;
a = b;
b = c;
}
return a;
}
};

lintcode bugfree and good codestyle note的更多相关文章

  1. leetcode & lintcode for bug-free

    刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be it ...

  2. leetcode bugfree note

    463. Island Perimeterhttps://leetcode.com/problems/island-perimeter/就是逐一遍历所有的cell,用分离的cell总的的边数减去重叠的 ...

  3. leetcode & lintcode 题解

    刷题备忘录,for bug-free 招行面试题--求无序数组最长连续序列的长度,这里连续指的是值连续--间隔为1,并不是数值的位置连续 问题: 给出一个未排序的整数数组,找出最长的连续元素序列的长度 ...

  4. [LintCode]——目录

    Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...

  5. (lintcode全部题目解答之)九章算法之算法班题目全解(附容易犯的错误)

    --------------------------------------------------------------- 本文使用方法:所有题目,只需要把标题输入lintcode就能找到.主要是 ...

  6. [LintCode] Implement Trie 实现字典树

    Implement a trie with insert, search, and startsWith methods. Have you met this question in a real i ...

  7. LintCode Subtree

    原题链接在这里:http://www.lintcode.com/en/problem/subtree/ You have two every large binary trees: T1, with ...

  8. Lintcode: Majority Number III

    Given an array of integers and a number k, the majority number is the number that occurs more than 1 ...

  9. (二分查找 拓展) leetcode 162. Find Peak Element && lintcode 75. Find Peak Element

    A peak element is an element that is greater than its neighbors. Given an input array nums, where nu ...

随机推荐

  1. Spring整合web开发

    正常整合Servlet和Spring没有问题的 public class UserServlet extends HttpServlet { public void doGet(HttpServlet ...

  2. 关于jqgrid数据不显示问题

    近日有个需求要用到jqgrid,原本用着一切都很顺利,但是在需求变动后,只是修改部分字段名称jqgrid就不显示数据了,后台数据也能传到前台,但是就是不给我显示,到嘴的肉就是没法吃,蛋疼,郁闷都无法形 ...

  3. Hdu 3564 Another LIS 线段树+LIS

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  4. BC一周年练习赛

    Souvenir  Accepts: 901  Submissions: 2743  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 262 ...

  5. CodeForces 544A

    You are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concat ...

  6. 将一个Asp.Net网站改为MVC

    背景:   网站已经开发的一部分 主要是Web服务和API  现在要做一些给人看的页面 转载请注明出处 http://www.cnblogs.com/zaiyuzhong/p/add-mvc-in-w ...

  7. poj2689Prime Distance 素数测试

    朴素素数测试是O(x1/2)的,每一个数都测试下来就炸了 然而如果全部预处理的话才是做大死,时间空间各种炸(大约有1亿个数) 所以怎么平衡一下呢? 其实在预处理的时候可以只处理一半:把21474836 ...

  8. 酷炫放大镜canvas实现

    主要采用了canvas内渲染canvas的技术,还有利用比例来放大图片 比例:放大镜宽度/画布宽度=原图宽度/渲染图宽度 <!DOCTYPE html><html lang=&quo ...

  9. javascript平时例子⑩(表情发送)

    <!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...

  10. JavaScript-table+大图滚动

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...