Fibonacci sequence:
This question is slightly different from the initial value of Frog Jumping Step-2, it needs to be clear, the state transition equation is the same
class Solution {
public:
int fib(int n) {
if (n <= 1) return n;
int first = 0;
int second = 1;
int thrid;
for (int i = 2; i <= n; ++i) {
thrid = (first + second) % 1000000007;
first = second;
second = thrid;
}
return thrid;
}
};