日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Leetcode 746. Min Cost Climbing Stairs

發布時間:2025/7/25 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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:?Paint Fence?Coin Change?Maximum Sum of 3 Non-Overlapping Subarrays

轉載于:https://www.cnblogs.com/Deribs4/p/8330522.html

總結

以上是生活随笔為你收集整理的Leetcode 746. Min Cost Climbing Stairs的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。