You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
class Solution {
public:
int climbStairs(int n) {
/* recursive
if(n<=0) return 0;
else if(n==1) return 1;
else if(n==2) return 2;
else return climbStairs(n-1) + climbStairs(n-2);
*/
if(n <= 0) return 0;
vector<int> v = vector<int>();
v.push_back(1);
v.push_back(2);
while(v.size() < n) v.push_back(v[v.size()-1] + v[v.size()-2]);
return v[n-1];
}
};