与题目一基本一致https://blog.csdn.net/Dejan520/article/details/123590239
求结果除以1000000007的余数。1000000007就是一个很大的素数,避免结果过大溢出的问题
class Solution {
public:
int numWays(int n) {
if(n==0)return 1;
if(n==1)return 1;
int l =1,r =1,sum =1;
for(int i=2;i<=n;++i){
sum = (l+r)%1000000007;
l =r;
r =sum;
}
return sum;
}
};