Link: Snap
Method: use recursion
Then look at the code
class Solution {
public:
int fib(int n) {
int mod = 1000000007;
if(n<2)
{
return n;
}
else{
return ((fib(n-1)+fib(n-2))%mod);
}
}
};
In the end, it can run through half of the use cases, because the complexity of recursion is high.