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 };
复制代码

 


本文转自ZH奶酪博客园博客,原文链接:http://www.cnblogs.com/CheeseZH/p/4998683.html,如需转载请自行联系原作者

相关文章
Fibonacci斐波那契数列的几种题型
Fibonacci斐波那契数列的几种题型
104 0
【欧拉计划第 2 题】Even Fibonacci numbers
【欧拉计划第 2 题】Even Fibonacci numbers
【欧拉计划第 2 题】Even Fibonacci numbers
ZCMU - 1990: Fibonacci
ZCMU - 1990: Fibonacci
86 0
[LintCode] Two Sum 两数之和
Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the tw.
1362 0