diff --git a/problems/0746.使用最小花费爬楼梯.md b/problems/0746.使用最小花费爬楼梯.md index 5ddcae0f..1e8e8038 100644 --- a/problems/0746.使用最小花费爬楼梯.md +++ b/problems/0746.使用最小花费爬楼梯.md @@ -225,7 +225,16 @@ class Solution { ``` Python: - +```python +class Solution: + def minCostClimbingStairs(self, cost: List[int]) -> int: + dp = [0] * (len(cost)) + dp[0] = cost[0] + dp[1] = cost[1] + for i in range(2, len(cost)): + dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i] + return min(dp[len(cost) - 1], dp[len(cost) - 2]) +``` Go: ```Go