Fibonacci sequence:
class Solution {
public:
int numWays(int n) {
if (0 == n || 1 == n) return 1;
if (2 == n) return 2;
int first = 1, second = 2;
int third;
for (int i = 3; i <=n; ++i) {
third = (first + second) % 1000000007;
first = second;
second = third;
}
return third;
}
};