首页 > 其他 > 详细

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

时间:2020-12-21 15:11:30      阅读:20      评论:0      收藏:0      [点我收藏+]

题目链接: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;
    }
}

 

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

原文:https://www.cnblogs.com/liuyongyu/p/14167316.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!