题目描述
你在爬楼梯,需要n步才能爬到楼梯顶部
每次你只能向上爬1步或者2步。有多少种方法可以爬到楼梯顶部?
public int climbStairs (int n) {
if(n==1 || n==0){
return 1;
}
int[] step = new int[n+1];
step[1]=1;
step[2]=2;
//第i步的方法 = 第i-1步的方法+第i-2步的方法
for(int i=3;i<=n;i++){
step[i]=step[i-1]+step[i-2];
}
return step[n];
}