lintcode bugfree and good codestyle note
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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; } };
以上是关于lintcode bugfree and good codestyle note的主要内容,如果未能解决你的问题,请参考以下文章
lintcode-easy-Partition Array by Odd and Even
[LintCode] Add and Search Word 添加和查找单词
[Lintcode]7. Serialize and Deserialize Binary Tree/[Leetcode]297. Serialize and Deserialize Binary T
lintcode-medium-Construct Binary Tree from Inorder and Postorder Traversal
lintcode-medium-Construct Binary Tree from Preorder and Inorder Traversal