不用递归的方法更快
int fib(int n){if (n == 0) return 0;if (n == 1) return 1;long long result = 0, f1 = 0, f2 = 1;for (unsigned int i = 2;i <= n; ++i) {result = (f1 + f2) % 1000000007;f1 = f2;f2 = result;}return result;}
leedcode通过:
执行用时:0 ms, 在所有 C 提交中击败了100.00% 的用户内存消耗:5.4 MB, 在所有 C 提交中击败了55.67% 的用户
