[剑指Offer] 7.斐波那契数列
1 class Solution { 2 public: 3 int Fibonacci(int n) { 4 int res[40] = {0}; 5 res[0] = 1; 6 res[1] = 1; 7 for(int i = 2;i < n;i ++){ 8 res[i] = res[i - 1] + res[i - 2]; 9 } 10 return res[n - 1]; 11 } 12 };
1 class Solution { 2 public: 3 int Fibonacci(int n) { 4 int res[40] = {0}; 5 res[0] = 1; 6 res[1] = 1; 7 for(int i = 2;i < n;i ++){ 8 res[i] = res[i - 1] + res[i - 2]; 9 } 10 return res[n - 1]; 11 } 12 };