Merge pull request #1791 from roylx/master

Update 0746.使用最小花费爬楼梯.md 添加Python不支付费用版本
This commit is contained in:
程序员Carl 2022-12-20 11:01:44 +08:00 committed by GitHub
commit 72d8fa4fcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -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) + 1)