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 ...
随机推荐
- 【剑指offer】顺时针打印矩阵,C++实现
原创文章,转载请注明出处! 博客文章索引地址 1.题目 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵,则依次打印出数字1,2,3,4,8,12,16,15,14 ...
- kubeadm搭建kubernetes集群之一:构建标准化镜像
使用docker可以批量管理多个容器,但都是在同一台电脑内进行的,这在实际生产环境中是不够用的,如何突破单机的限制?让多个电脑上的容器可以像单机上的docker-compose.yml管理的那样方便呢 ...
- sha1的加密
from hashlib import sha1 #给password加密s1 = sha1() #创建sha1加密对象s1.update(password.encode("utf-8&qu ...
- HP G7服务器添加新硬盘
1. 停掉 服务器(必须停了服务器),插入新硬盘.开机,出现F9和F11的时候,按下F5(这个很坑爹,没有显示F5进入阵列配置),进入阵列控制界面之后按出现红色的提示后按下F8进入阵列控制管理界面.进 ...
- NGUI动态给EventDelegate加参数
示例代码如下: 响应的函数声明为: void OnChange(UIToggle toggle) { if(toggle.value) { // do something } } 添加响应的代码如 ...
- js 字符串和数组注意点
var a="foo"; var b=[ "f","o","o"]; a[1]="o"; b[1]= ...
- Tomcat 配置虚拟路径保存、访问图片
转载自:https://www.cnblogs.com/magic101/p/7756402.html 配置tomcat的虚拟映射路径 1.修改Tomcat的server.xml文件 <Host ...
- BZOJ1085 SCOI2005 骑士精神【IDA* 启发式迭代加深】
BZOJ1085 SCOI2005 骑士精神 Description 在一个5×5的棋盘上有12个白色的骑士和12个黑色的骑士, 且有一个空位.在任何时候一个骑士都能按照骑士的走法(它可以走到和它横坐 ...
- spring--注入方式
1.正常方式: 在一个“value”标签注入值,并附有“property”标签结束. <beans xmlns="http://www.springframework.org/sche ...
- minio 安装以及使用
1. 为了方便使用 docker 安装 docker run -p 9000:9000 minio/minio server /export 注意启动显示的 appkey secretkey C ...