(Easy) Min Cost Climbing Stairs - LeetCode
时间:2019-08-21
本文章向大家介绍(Easy) Min Cost Climbing Stairs - LeetCode,主要包括(Easy) Min Cost Climbing Stairs - LeetCode使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
Description:
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]
.
Accepted
93,418
Submissions
194,715
Solution
class Solution { public int minCostClimbingStairs(int[] cost) { if(cost==null||cost.length==0){ return 0; } int [] dp = new int[cost.length]; dp[0]= cost[0]; dp[1]= cost[1]; for(int i =2; i< dp.length; i++){ dp[i] = cost[i]+ Min(dp[i-1],dp[i-2]); } return Min(dp[cost.length-1],dp[cost.length-2]); } int Min(int a, int b){ return a>b? b:a; } }
原文地址:https://www.cnblogs.com/codingyangmao/p/11391352.html
- 树莓派与arduino通信
- process information unavailable 的解决办法
- JS魔法堂:再识IE的内存泄露
- 给树莓派安装中文字库
- Hadoop(十七)之MapReduce作业配置与Mapper和Reducer类
- Design Pattern: Observer Pattern
- Hadoop(十六)之使用Combiner优化MapReduce
- ActiveMQ笔记(6):消息延时投递
- CentOS 安装 Maven
- Architecture Pattern: Publish-subscribe Pattern
- OOAD-设计模式(三)之创建型设计模式(5种)
- ActiveMQ笔记(5):JMX监控
- session失效时间设置
- ActiveMQ笔记(4):搭建Broker集群(cluster)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- R语言进阶之时间序列分析
- Spring Boot 实现员工信息管理demo
- 如何把 Flutter 云端一体化做到极致?
- 微服务[学成在线] day16:基于Spring Security Oauth2开发认证服务
- 新的跨域策略:使用COOP、COEP为浏览器创建更安全的环境
- CVE-2020-1948:Dubbo Provider默认反序列化复现
- R语言进阶之因子分析
- Spring Boot 整合Thymeleaf
- Spring Boot 整合Shiro
- 微服务[学成在线] day01:CMS接口开发
- 微服务[学成在线] day02:CMS前端开发
- ggplot2| 绘制KEGG气泡图
- 微服务[学成在线] day03:CMS页面管理开发
- ggplot2|绘制GO富集柱形图
- 使用Prometheus监控Flink