From c7c3d8febf477054cefd6b243d07dc3cb512ad00 Mon Sep 17 00:00:00 2001 From: ChrisLin Date: Sun, 6 Jun 2021 22:19:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A00746.=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=9C=80=E5=B0=8F=E8=8A=B1=E8=B4=B9=E7=88=AC=E6=A5=BCJavaScrip?= =?UTF-8?q?t=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0746.使用最小花费爬楼梯.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/problems/0746.使用最小花费爬楼梯.md b/problems/0746.使用最小花费爬楼梯.md index 1e8e8038..4238a389 100644 --- a/problems/0746.使用最小花费爬楼梯.md +++ b/problems/0746.使用最小花费爬楼梯.md @@ -255,7 +255,18 @@ func min(a, b int) int { } ``` - +Javascript: +```Javascript +var minCostClimbingStairs = function(cost) { + const dp = [ cost[0], cost[1] ] + + for (let i = 2; i < cost.length; ++i) { + dp[i] = Math.min(dp[i -1] + cost[i], dp[i - 2] + cost[i]) + } + + return Math.min(dp[cost.length - 1], dp[cost.length - 2]) +}; +``` ----------------------- * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)