思路:动态规划。

 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. java基础-day14

    第01天 java面向对象 今日内容介绍 u 接口 u 匿名对象&final u 多态 第1章   接口 1.1  接口的概述 接口是功能的集合,同样可看做是一种数据类型,是比抽象类更为抽象的 ...

  2. Android webview 退出时关闭声音 4.视频全屏 添加cookie

    全屏问题,可以参考 http://bbs.csdn.net/topics/390839259,点击 webView = (WebView) findViewById(R.id.webView); vi ...

  3. Hdu1016 Prime Ring Problem(DFS) 2016-05-06 14:27 329人阅读 评论(0) 收藏

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  4. Android-Kotlin-set/get方法的使用

    Student.kt package cn.kotlin.kotlin_oop04 open class Person { open var personName:String = "我是父 ...

  5. Martin Fowler 分层测试概念博文分享

    在我们测试工作中,常常遇到这样的问题:开发与测试团队分属不同的不同(部门隔离.沟通不畅),质量职责划分不清(出现bug往往都是测试人员背锅),需求的不确定和易变性(需求不断变化导致代码不停更新.产品重 ...

  6. 1.翻译:EF基础系列--什么是Entity Framework?

    大家好,好久不见,EF系列之前落下了,还是打算重新整理一下. 先说说目前的打算:先简单了解一下EF基础系列-->然后就是EF 6 Code-First系列-->接着就是EF 6 DB-Fi ...

  7. java面试和笔试

    1.Java中异常处理机制和事件机制. 2.String是最基本的数据类型吗? 基本数据类型包括byte.int.char.long.float.double.boolean和short. java. ...

  8. AJPFX技术分析入门

    AJPFX:技术分析入门 技术分析就是指通过考察历史数据来预测未来价格走向.外汇市场是非常讲技术分析的,而且分析师的基本功就是技术分析,但是,没有对基本面的准确把握,技术分析就会含糊.但是技术分析究其 ...

  9. Python中super()的用法

    参考链接:https://www.cnblogs.com/shengulong/p/7892266.html super 是用来解决多重继承问题的,直接用类名调用父类方法在使用单继承的时候没问题,但是 ...

  10. Swift5 语言参考(九) 泛型和参数

    本章介绍泛型类型,函数和初始值设定项的参数和参数.声明泛型类型,函数,下标或初始化程序时,可以指定泛型类型,函数或初始化程序可以使用的类型参数.当创建泛型类型的实例或调用泛型函数或初始化程序时,这些类 ...