leetcode-Min Cost Climbing Stairs
题目:
On a staircase, the i
-th step has some non-negative cost cost[i]
assigned (0 indexed).
Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of the floor, and you can either start from the step with index 0, or the step with index 1.
Example 1:
Input: cost = [10, 15, 20]
Output: 15
Explanation: Cheapest is start on cost[1], pay that cost and go to the top.
Example 2:
Input: cost = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1]
Output: 6
Explanation: Cheapest is start on cost[0], and only step on 1s, skipping cost[3].
Note:
cost
will have a length in the range[2, 1000]
.- Every
cost[i]
will be an integer in the range[0, 999]
.
class Solution:
def minCostClimbingStairs(self, cost):
"""
:type cost: List[int]
:rtype: int
"""
cost0, cost1 = cost[0], cost[1]
for c in cost[2:]:
cost0, cost1 = cost1, min(cost0, cost1) + c
return min(cost0, cost1)
leetcode-Min Cost Climbing Stairs的更多相关文章
- [LeetCode] Min Cost Climbing Stairs 爬楼梯的最小损失
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...
- Python3解leetcode Min Cost Climbing Stairs
问题描述: On a staircase, the i-th step has some non-negative cost cost[i]assigned (0 indexed). Once you ...
- Min Cost Climbing Stairs - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Min Cost Climbing Stairs - LeetCode 注意点 注意边界条件 解法 解法一:这道题也是一道dp题.dp[i]表示爬到第i层 ...
- LeetCode 746. 使用最小花费爬楼梯(Min Cost Climbing Stairs) 11
746. 使用最小花费爬楼梯 746. Min Cost Climbing Stairs 题目描述 数组的每个索引做为一个阶梯,第 i 个阶梯对应着一个非负数的体力花费值 cost[i].(索引从 0 ...
- Leetcode之动态规划(DP)专题-746. 使用最小花费爬楼梯(Min Cost Climbing Stairs)
Leetcode之动态规划(DP)专题-746. 使用最小花费爬楼梯(Min Cost Climbing Stairs) 数组的每个索引做为一个阶梯,第 i个阶梯对应着一个非负数的体力花费值 cost ...
- leetcode 746. Min Cost Climbing Stairs(easy understanding dp solution)
leetcode 746. Min Cost Climbing Stairs(easy understanding dp solution) On a staircase, the i-th step ...
- LN : leetcode 746 Min Cost Climbing Stairs
lc 746 Min Cost Climbing Stairs 746 Min Cost Climbing Stairs On a staircase, the i-th step has some ...
- 746. Min Cost Climbing Stairs@python
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...
- 【Leetcode_easy】746. Min Cost Climbing Stairs
problem 746. Min Cost Climbing Stairs 题意: solution1:动态规划: 定义一个一维的dp数组,其中dp[i]表示爬到第i层的最小cost,然后来想dp[i ...
- Min Cost Climbing Stairs [746]
Min Cost Climbing Stairs [746] 题目描述 简单来说就是:要跳过当前楼梯需要花费当前楼梯所代表的价值cost[i], 花费cost[i]之后,可以选择跳一阶或者两阶楼梯,以 ...
随机推荐
- SharpCompress的压缩文件解压和文件夹压缩
1.前言 最近做一个功能需要用到对压缩文件的解压,就找到了这个SharpCompress不错,还能解压rar的文件.但是网上的资料和我拿到的SharpCompress.dll的方法有些出入,所以我就自 ...
- Android 自定义光标样式
今天自定义光标,自己切图,不过怎么切都是很宽.不是一个很细的条.我用ps花了一个像素的直线,放上去还是不行.后来在网上找到方法,那就是用shape.不得不说,shape真的是太吊了. 给EditTex ...
- Docker容器 - 容器时间跟宿主机时间同步
在Docker容器创建好之后,可能会发现容器时间跟宿主机时间不一致,这就需要同步它们的时间,让容器时间跟宿主机时间保持一致. 转载自:https://www.cnblogs.com/kevingrac ...
- laravel5.5队列
目录 简单实例 1. 简介和配置 1.1 好处 1.2 配置文件 1.3 队列驱动的必要配置 2. 创建任务 2.1 生成任务类 2.2 修改任务类 2.3 分发任务 2.4 自定义队列 & ...
- SpringMVC 集成 Freemarker 模板引擎
本文通过 maven 项目中集成 1.引入 SpringMVC 与 Freemarker 需要的依赖 <!-- SpringMVC --> <dependency> <g ...
- Restful API实战
简介:随着移动互联网的发展,客户端层出不穷,app,web,微信端等等,而后端业务逻辑基于是一致的,如何做到业务逻辑“一次编写,随时接入”?答案是通过远程调用API,而目前比较火的方案是“Restfu ...
- django的F和Q对象
F表达式和Q表达式: # 示例模型如下 class Book(models.Model): """图书模型""" name = models ...
- Android记事本开发02
今天: 继续学习基础知识. 昨天: 学习了ADB工具的基本命令. Android项目的目录结构. AndroidManifest.xml Android应用程序的打包和安装 遇到的问题: 无.
- 移动平台自动化测试:appium(一)
Appium 是一个开源的,跨平台的自动化测试工具.它支持模拟器(iOS,FirefoxOS,Android)和真机(iOS, Android, FirefoxOS)上的原生应用,混合应用和移动 we ...
- SqlServer中截取小数位数
方法一:convert(float,字段名) as 别名 select convert(float,round(10.123232,2)) 结果:10.12 select convert(float, ...