Problem here
Problem
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?
Solution
這題之前做過
就是超級樓梯那條
class Solution {
public:
int climbStairs(int n) {
vector<int> f;
f.push_back(1);
f.push_back(1);
for(int i = 2; i <= n; i++){
f.push_back(f[i-1] + f[i-2]);
}
return f[n];
}
};