C++
1 class Solution { 2 public: 3 int Fibonacci(int n) { 4 if (n == 0) return 0; 5 if (n <= 2) return 1; 6 7 int a = 1, b = 1; 8 while(n-- > 2) { 9 a = a + b; 10 b = a - b; 11 } 12 return a; 13 14 } 15 };
本文转自ZH奶酪博客园博客,原文链接:http://www.cnblogs.com/CheeseZH/p/5112887.html,如需转载请自行联系原作者