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
- 下一篇: 基础数据类型初识