LC最简单的题目?
public class Solution {
public int climbStairs(int n) {
if(n<=0) return 0;
if(n==1) return 1;
if(n==2) return 2;
int ways = 0, one_step_before =2, two_step_before = 1;
for(int i=3; i<= n; i++) {
ways = one_step_before + two_step_before;
two_step_before = one_step_before;
one_step_before = ways;
}
return ways;
}
}
网友评论