lintcode bugfree and good codestyle note

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 = 0, b = 1;
        for (int i = 1; i < n; i++) {
            int c = a + b;
            a = b;
            b = c;
        }
        return a;
    }
};
View Code
原文地址:https://www.cnblogs.com/maizi-1993/p/6130092.html