LintCode:Fibonacci

 

C++

 1 class Solution{
 2 public:
 3     /**
 4      * @param n: an integer
 5      * @return an integer f(n)
 6      */
 7     int fibonacci(int n) {
 8         // write your code here
 9         int a=0,b=1;
10         for (int i=1; i<n; i++) {
11             a = a+b;
12             b = a-b;
13         }
14         return a;
15     }
16 };

 

posted @ 2015-11-26 19:19  ZH奶酪  阅读(251)  评论(0编辑  收藏  举报