Loading

Leetcode.746使用最小费用爬楼梯

题目链接:746使用最小费用爬楼梯

代码:

class Solution {
    public int minCostClimbingStairs(int[] cost) {
        int fir, sec;
        fir = sec = 0;
        for(int i=2; i<=cost.length; i++){
            int t = Math.min(fir+cost[i-1], sec+cost[i-2]);
            sec = fir;
            fir = t;
        }
        return fir;
    }
}

 

posted @ 2020-12-21 12:36  yoyuLiu  阅读(80)  评论(0编辑  收藏  举报