From 294c8db68e1635bf9d87cc0b3990b3a4400c9e7b Mon Sep 17 00:00:00 2001 From: roylx <73628821+roylx@users.noreply.github.com> Date: Thu, 1 Dec 2022 11:40:50 -0700 Subject: [PATCH] =?UTF-8?q?Update=200746.=E4=BD=BF=E7=94=A8=E6=9C=80?= =?UTF-8?q?=E5=B0=8F=E8=8A=B1=E8=B4=B9=E7=88=AC=E6=A5=BC=E6=A2=AF.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加Python不支付费用版本 --- problems/0746.使用最小花费爬楼梯.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/problems/0746.使用最小花费爬楼梯.md b/problems/0746.使用最小花费爬楼梯.md index b6f5a734..a2865aed 100644 --- a/problems/0746.使用最小花费爬楼梯.md +++ b/problems/0746.使用最小花费爬楼梯.md @@ -241,6 +241,17 @@ class Solution { ### Python ```python +# 第一步不支付费用 +class Solution: + def minCostClimbingStairs(self, cost: List[int]) -> int: + n = len(cost) + dp = [0]*(n+1) # 到达前两步费用为0 + for i in range(2, n+1): + dp[i] = min(dp[i-1]+cost[i-1], dp[i-2]+cost[i-2]) + return dp[-1] +``` +```python +# 第一步支付费用 class Solution: def minCostClimbingStairs(self, cost: List[int]) -> int: dp = [0] * (len(cost))