leetcode746
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的更多相关文章
- [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 ...
- Leetcode746.Min Cost Climbing Stairs使用最小花费爬楼梯
数组的每个索引做为一个阶梯,第 i个阶梯对应着一个非负数的体力花费值 cost[i](索引从0开始). 每当你爬上一个阶梯你都要花费对应的体力花费值,然后你可以选择继续爬一个阶梯或者爬两个阶梯. 您需 ...
- leetcode746 Min Cost Climbing Stairs
""" On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 inde ...
- 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 ...
随机推荐
- erlang游戏开发tcp
之前在开发游戏的时候我们采用smartfoxserver这个java开发的游戏引擎,这个引擎在开发回合制游戏方面速度还是不错的.但是面对客户日益增长的需求还是有些力不从心.比如集群,比如灾备,热切换, ...
- slam学习
学习内容: 数学: 线性代数,概率论, 优化理论,离散数学, 李代数, 凸优化: 算法: 概率机器人, 机器人状态估计, 深度学习,非线性优化: 工程: c/c++ , python, ros, ...
- 3DsMax动画插件
* 简易骨骼动画: Mesh当前帧顶点 = Mesh绑定时顶点 * 绑定时骨骼的变换到本帧骨骼的变换的改变量. = Mesh绑定时顶点 * 绑定时骨骼的变换的逆矩阵 * 本帧的骨骼变换. = Mesh ...
- linux自学(五)之开始centos学习,Xshell远程连接
上一篇:linux自学(四)之开始centos学习,网络配置 前面操作都是在电脑中的虚拟机上操作的,比较麻烦,需要来回切换.下面我将使用远程连接工具Xshell进行操作,Xshell直接百度下载即可. ...
- Java并发--如何创建线程
下面是本文的目录大纲: 一.Java中关于应用程序和进程相关的概念 二.Java中如何创建线程 三.Java中如何创建进程 转载原文链接:http://www.cnblogs.com/dolphin0 ...
- 一个简洁、好用的Pytorch训练模板
一个简洁.好用的Pytorch训练模板 代码地址:https://github.com/KinglittleQ/Pytorch-Template 怎么使用 1) 更改template.py 替换 __ ...
- 接口测试框架——第二篇-python读取excel文件内容
今天完善excel_module.py文件,上代码: # coding: utf-8 import xlrd class ReadExcel(): def __init__(self, file_na ...
- NanoPiM1开箱测试
等了快一周了,终于那M1与那外壳一起给我寄过来了. 上午收到,开箱图就不亮了,来一上好电的图! 一同购买来的MSD卡里什么也没有,上电测试时只看到绿色的灯微微亮(这是一个BUG吗!!!!哈哈). 所以 ...
- ubuntu 进入单用户模式
进入单用户模式: 按shift进入 1.开机到grub时,用上下键移到第二行的恢复模式,按e(注意不是回车) 即Ubuntu,With Linux 3.2.0-23-generic(recovery ...
- spring cache之自定义keys的过期时间
spring @cacheable注解默认不支持方法级别的缓存失效时间,只能通过配置来配置全局的失效时间 如果需要实现对方法级别的缓存支持失效时间机制,有一种比较简单的方法,spring配置文件如下: ...