From e67b7acaecb03440cf644930a69f9f45bff04743 Mon Sep 17 00:00:00 2001 From: reoaah Date: Thu, 20 May 2021 15:25:52 +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=BC=E6=A2=AF?= =?UTF-8?q?.md=20Go=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0746.使用最小花费爬楼梯.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/problems/0746.使用最小花费爬楼梯.md b/problems/0746.使用最小花费爬楼梯.md index b8158205..aff56208 100644 --- a/problems/0746.使用最小花费爬楼梯.md +++ b/problems/0746.使用最小花费爬楼梯.md @@ -228,7 +228,23 @@ Python: Go: +```Go +func minCostClimbingStairs(cost []int) int { + dp := make([]int, len(cost)) + dp[0], dp[1] = cost[0], cost[1] + for i := 2; i < len(cost); i++ { + dp[i] = min(dp[i-1], dp[i-2]) + cost[i] + } + return min(dp[len(cost)-1], dp[len(cost)-2]) +} +func min(a, b int) int { + if a < b { + return a + } + return b +} +```