Leetcode 746. Min Cost Climbing Stairs
生活随笔
收集整理的这篇文章主要介绍了
Leetcode 746. Min Cost Climbing Stairs
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
思路:动态规划。
1 class Solution { 2 //不能对cost数组进行写操作,因为JAVA中参数是引用 3 public int minCostClimbingStairs(int[] cost) { 4 int cost_0 = cost[0], cost_1 = cost[1]; 5 for(int i = 2; i < cost.length; i++) { 6 int cost_2 = Math.min(cost_0, cost_1) + cost[i]; 7 cost_0 = cost_1; 8 cost_1 = cost_2; 9 } 10 return Math.min(cost_0, cost_1); 11 } 12 }Next challenges:
转载于:https://www.cnblogs.com/Deribs4/p/8330522.html
总结
以上是生活随笔为你收集整理的Leetcode 746. Min Cost Climbing Stairs的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Codeforces757E.Bash
- 下一篇: 基础数据类型初识