题解 | #斐波那契数列#
斐波那契数列
http://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3
public class Solution {
public int Fibonacci(int n) {
if (n < 1) return n;
int[] fib = new int[3];
fib[0] = 0;
fib[1] = 1;
for (int i = 2; i <= n; i++) {
fib[i % 3] = fib[(i - 1) % 3] + fib[(i - 2) % 3];
}
return fib[n % 3];
}
}