思路:动态规划。

 class Solution {
//不能对cost数组进行写操作,因为JAVA中参数是引用
public int minCostClimbingStairs(int[] cost) {
int cost_0 = cost[0], cost_1 = cost[1];
for(int i = 2; i < cost.length; i++) {
int cost_2 = Math.min(cost_0, cost_1) + cost[i];
cost_0 = cost_1;
cost_1 = cost_2;
}
return Math.min(cost_0, cost_1);
}
}

Next challenges: Paint Fence Coin Change Maximum Sum of 3 Non-Overlapping Subarrays

Leetcode 746. Min Cost Climbing Stairs的更多相关文章

  1. 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 ...

  2. 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 ...

  3. [LeetCode] 746. Min Cost Climbing Stairs 爬楼梯的最小损失

    On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...

  4. Leetcode 746. Min Cost Climbing Stairs 最小成本爬楼梯 (动态规划)

    题目翻译 有一个楼梯,第i阶用cost[i](非负)表示成本.现在你需要支付这些成本,可以一次走两阶也可以走一阶. 问从地面或者第一阶出发,怎么走成本最小. 测试样例 Input: cost = [1 ...

  5. LeetCode 746. Min Cost Climbing Stairs (使用最小花费爬楼梯)

    题目标签:Dynamic Programming 题目给了我们一组 cost,让我们用最小的cost 走完楼梯,可以从index 0 或者 index 1 出发. 因为每次可以选择走一步,还是走两步, ...

  6. 【Leetcode_easy】746. Min Cost Climbing Stairs

    problem 746. Min Cost Climbing Stairs 题意: solution1:动态规划: 定义一个一维的dp数组,其中dp[i]表示爬到第i层的最小cost,然后来想dp[i ...

  7. 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 ...

  8. [LC] 746. Min Cost Climbing Stairs

    On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...

  9. 【Leetcode】746. Min Cost Climbing Stairs

    题目地址: https://leetcode.com/problems/min-cost-climbing-stairs/description/ 解题思路: 官方给出的做法是倒着来,其实正着来也可以 ...

随机推荐

  1. 在Echarts 柱形图的单击事件中写入自定义的参数

    标签: 逻辑:(点击柱形图的某个实例(注意:三个柱子表示的是一个实例)) 参考链接:http://echarts.baidu.com/doc/example/event.html { name: ‘c ...

  2. URAL1099. Work Scheduling(一般图匹配带花树开花算法)

    1099. Work Scheduling Time limit: 0.5 second Memory limit: 64 MB There is certain amount of night gu ...

  3. 3、利用GDB进行程序调试

    本文将用一个实际例子讲解如何通过GDB进行程序调试. 首先,我们需要理解的是GDB是GNU开源组织发布的一个强大的UNIX下的程序调试工具,其产生和调试的目的是让调试者知道,程序在执行时内部发生了什么 ...

  4. bootstrap1.3

    <html>   <head>   <meta charset="UTF-8">   <title></title>   ...

  5. NW.js安装原生node模块node-printer控制打印机

    1.安装原生node模块 #全局安装nw-gyp npm install -g nw-gyp #设置目标NW.js版本 set npm_config_target=0.31.4 #设置构建架构,ia3 ...

  6. Python——面向对象(初级篇)

    1.如何创建类 class 类名: pass 2.如何创建方法 构造方法: __init__ obj = 类名('a1') 普通方法: obj = 类名('xxx') obj.普通方法名() 3.图解 ...

  7. .netcore-FreeSql的使用-搭建context

    之前用netcore搭建了一个小项目,数据库操作用的是要手写sql语句的connection和command,一直想调个EFCore或者类似SOA那样的框架 今天看到了DotNet公众号提到的.NET ...

  8. 【BZOJ3709】 [PA2014]Bohater(贪心)

    传送门 BZOJ Solution 考虑如果可以回血肯定要打,那么就是按照伤害值从小到大排个序能打就打,不能打就\(NIE\). 接着看不能够回血的,emmm,把这个过程反着看一下就是打一个怪扣\(a ...

  9. 2018 Multi-University Training Contest 5

    (叹气.jpg) B.Beautiful Now 题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6351 题意:给一串长度为m的数字,k次任意交换其中 ...

  10. mac终端常用命令

    1.du #查看文件目录大小 示例:查看DataCenter目录下所有文件/文件夹的大小 everSeeker:DataCenter pingping$ -h .9G ./Books 1.2M ./C ...