牛客网-《剑指offer》-斐波那契数列

it2022-05-20  72

题目:http://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3

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 };

 

转载于:https://www.cnblogs.com/CheeseZH/p/5112887.html


最新回复(0)