美文网首页
70. Climbing Stairs

70. Climbing Stairs

作者: 沉睡至夏 | 来源:发表于2016-12-17 09:33 被阅读10次

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;
    }
}

相关文章

网友评论

      本文标题:70. Climbing Stairs

      本文链接:https://www.haomeiwen.com/subject/seuomttx.html