class Solution {
public:
int minCostClimbingStairs(vector<int>& cost) {
vector<int> totol(cost.size(), );
totol[] = cost[], totol[] = cost[];
for (int i = ; i < cost.size(); i++) {
totol[i] = min(totol[i - ] + cost[i], totol[i - ] +cost[i]);
}
return min(totol[cost.size() - ], totol[cost.size() - ]);
}
};

下面是C#版本的:

public class Solution
{
public int MinCostClimbingStairs(int[] cost)
{
var total = new List<int>();
total.Add(cost[]);//第0阶台阶的最小总花费
total.Add(Math.Min(cost[], cost[] + cost[]));//第1节台阶的最小总花费 for (int i = ; i < cost.Length; i++)
{
//当前台阶的最小总花费=当前台阶的直接花费+ min(当前-1节总花费 , 当前-2节总花费)
total.Add(cost[i] + Math.Min(total[i - ], total[i - ]));
}
//最后上到楼梯顶,可能踩倒数第一节或者倒数第二节。选择其中小的
return Math.Min(total[cost.Length - ], total[cost.Length - ]);
}
}

leetcode746的更多相关文章

  1. [Swift]LeetCode746. 使用最小花费爬楼梯 | Min Cost Climbing Stairs

    On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...

  2. Leetcode746.Min Cost Climbing Stairs使用最小花费爬楼梯

    数组的每个索引做为一个阶梯,第 i个阶梯对应着一个非负数的体力花费值 cost[i](索引从0开始). 每当你爬上一个阶梯你都要花费对应的体力花费值,然后你可以选择继续爬一个阶梯或者爬两个阶梯. 您需 ...

  3. leetcode746 Min Cost Climbing Stairs

    """ On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 inde ...

  4. LeetCode746 Min Cost Climbing Stairs(爬上楼梯的最小损失)

    题目 On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you p ...

随机推荐

  1. moment时间转换插件

    在vue中的使用: import moment = from “moment” Vue.prototype.$moment = moment; 获取时间戳 : var res = this.$mome ...

  2. 使用阿里云加速docker镜像的安装

    刚接触docker,尝试安装node镜像.docker运行在win7中,安装完Docker Toolbox之后简单敲了docker pull node命令,然后就是漫长的等待了… 等待的结果就是nod ...

  3. BZOJ3438:小M的作物 (最大闭合权图->最小割)

    小M在MC里开辟了两块巨大的耕地A和B(你可以认为容量是无穷),现在,小P有n中作物的种子,每种作物的种子 有1个(就是可以种一棵作物)(用1...n编号),现在,第i种作物种植在A中种植可以获得ai ...

  4. Java并发--Timer和TimerTask

    下面内容转载自: http://blog.csdn.net/xieyuooo/article/details/8607220 其实就Timer来讲就是一个调度器,而TimerTask呢只是一个实现了r ...

  5. c语言标识符

    在程序中使用的变量名.函数名.标号等统称为标识符. 除库函数的函数名由系统定义外,其余都由用户自定义. C 规定,标识符只能是字母(A-Z,a-z).数字(0-9).下划线()组成的字符串,并且其第一 ...

  6. C#/.NET 匿名函数会捕获变量,并延长对象的生命周期

    小伙伴在一次垃圾回收中,发现对象并没有被回收掉,而注释掉一句代码后它便能够回收. 这究竟是为什么? 不关心探索过程的就直接拉到最后看结论吧!   探索 测试代码是这样的: private void O ...

  7. MySQL 根据身份证查找年龄段

    SELECT       idcard,YEAR (NOW()) - substring(idcard, 7, 4) as nFROM es_members where idcard >0 HA ...

  8. static类和no static类的区别

    1.static类,只能有静态成员,不能被实例.静态的东西在内存中只有一份,调用速度会快,但是相对费内存. 2.在另外一个类内部定义的类,此类的实例化不希望依赖外部类的实例化,此时可以定义为静态类(即 ...

  9. springboot使用hibernate validator校验方式

    一.参数校验 在开发中经常需要写一些字段校验的代码,比如字段非空,字段长度限制,邮箱格式验证等等,写这些与业务逻辑关系不大的代码个人感觉有两个麻烦: 验证代码繁琐,重复劳动 方法内代码显得冗长 每次要 ...

  10. qqbot 配置

    qqbot 配置 用起来还是挺方便的,使用 pip install qqbot 就可以. 不过找配置文件没注意,以为是在程序目前,原来是在 C:\Users\xxx.qqbot-tmp 目录. 插件可 ...