思路:动态规划。

 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. codeforces815A Karen and Game 2017-06-27 15:22 31人阅读 评论(0) 收藏

    C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...

  2. hdu 4915 括号匹配+巧模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=4915 给定一个序列,由()?组成,其中?可以表示(或者),问说有一种.多种或者不存在匹配. 从左向右,优先填满n ...

  3. UITabBarItem title 和self.title设置不同的标题

    self.navigationItem.title = @"my title"; //sets navigation bar title. self.tabBarItem.titl ...

  4. Opencv打开摄像头,读不到图像,一般来说先读取第一帧,舍弃,然后就正常了

    舍弃第一帧的程序: cap >> img; cv::waitKey(100);  if (cvWaitKey(5) == 27) break; cap >> img;

  5. Spring下配置几种常用连接池

    1.连接池概述 数据库连接是一种关键的有限的昂贵的资源,这一点在多用户的网页应用程序中体现得尤为突出.对数据库连接的管理能显著影响到整个应用程序的伸缩性和健壮性,影响到程序的性能指标.数据库连接池正是 ...

  6. MacOS统计TCP/UDP端口号与对应服务

    1.TCP端口 echo "### TCP LISTEN ###" lsof -nP -iTCP -sTCP:LISTEN 2.UDP端口 echo "### UDP L ...

  7. docker实用命令集合

    1. 访问docker中的MySQL数据库: docker exec -it test_mysql_1 mysql -u root -p 2. 用docker命令导入或导出mysql数据: 导出doc ...

  8. Python 数据类型之一:列表(list)

    本次内容主要是总结一下 Python 数据类型中的 list (列表),关于 list 我在 Python 学习第二章已经简单介绍过了,这次呢,我这边主要总结自己学到的跟大家分享一下,有什么不对或者更 ...

  9. Windows核心编程:第2章 字符和字符串处理

    Github https://github.com/gongluck/Windows-Core-Program.git //第2章 字符和字符串处理.cpp: 定义应用程序的入口点. // #incl ...

  10. C#开发邮件收发(同步)

    发邮件界面: 收邮件界面: 先分析邮件发送类 邮件发送类使用smtp协议,这里以QQ邮箱为例 using System; using System.Collections.Generic; using ...