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. 【剑指offer】不使用新变量,交换两个变量的值,C++实现

    # 题目 不使用新变量,交换两个变量的值. # 思路 方法一:使用加减法操作,交换两个变量的值. A = A+B B = A-B A = A-B 方法二:使用异或运算,交换两个变量的值 A = A^B ...

  2. hexo的环境搭建

    今天开始折腾下hexo,安装起来还是有点坑,简单记录下,会不断更新. 网上安装的文章多不胜数,当然首先还是得去看看官方的文档. 按照官方的文档,不知大家是否顺利,本人搭建环境的时候并不顺利. 明确要安 ...

  3. debian 8.1 安装idempiere 2.1 X64 笔记

    接上文.当虚拟服务器和虚拟机搭建完成后.登陆debian 8.1 X64. 进入虚拟服务器控制台.打开虚拟机.root登陆.(留好初始状态系统快照.以便系统恢复.) 由于之前debian8.1X64默 ...

  4. Unity Obstacle分析

    NavMeshObstacle Normal 通过设置半径和高度来设定障碍物,配合NavMesh使用. 优点: 简单易用,效率高 动态生成 缺点: 可能会被主角穿过,但目前没发现 形状固定为圆柱 Na ...

  5. keycloak 了解

    Keycloak 是一个针对Web应用和 RESTful Web 服务提供 SSO 集成.基于 OAuth 2.0 和 JSON Web Token(JWT) 规范.目前用于实现 JBoss 与 Wi ...

  6. Time complexity--codility

    lesson 3: Time complexity exercise: Problem: You are given an integer n. Count the total of 1+2+...+ ...

  7. zabbix 布署实践【8 监控windows server】

    参考http://www.cnblogs.com/likehua/p/3968689.html的思路,我安装的是zabbix 3.0 从zabbix官网下载windown的 Zabbix pre-co ...

  8. Makefile编写 四 函数篇

    一.函数的调用语法 函数调用与变量一样,也是以“$”来标识的,其语法如下: $(<function> <arguments>) 或是 ${<function> &l ...

  9. 手动封装OpenCV1.0的IplImage读取保存功能遇到的小问题

    最近准备重新学习图像处理的知识,主要目的是自己实现一遍图像处理的算法,所以除了读取.保存图像外的操作都自己写,没想到直接封装OpenCV的读取.保存功能的第一步就出错.关键代码如下 void MyIm ...

  10. GOF23设计模式之命令模式(command)

    一.命令模式概述 将一个请求封装到一个对象,从而使得可用不同的请求对客户进行参数化. 二.命令模式结构 (1)Command 抽象命令类 (2)ConcreteCommand 具体命令类 (3)Inv ...