class Solution {
public int fib(int n) {
final int MOD = 1000000007;
if (n == 0) {
return 0;
}
if (n == 1) {
return 1;
}
int first = 0, second = 1, res = 0;
for (int i = 2; i <= n; i++) {
res = (first + second) % MOD;
first = second;
second = res;
}
return res;
}
}
评论