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?
Note: Given n will be a positive integer.
解法1:记忆化数组
class Solution {
public:
int value[1000]={};
int climbStairs(int n) {
if(n==1)return 1;
else if(n==2)return 2;
else{
if(value[n-1]!=0){
int k=value[n-1];
int s=k+climbStairs(n-2);
value[n]=s;
return s;
}
else{
int s=climbStairs(n-1)+climbStairs(n-2);
value[n]=s;
return s;
}
}
}
};