Skip to content

Commit

Permalink
Update 0746.使用最小花费爬楼梯.md
Browse files Browse the repository at this point in the history
添加Python不支付费用版本
  • Loading branch information
roylx committed Dec 1, 2022
1 parent 39ecb52 commit 294c8db
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions problems/0746.使用最小花费爬楼梯.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 294c8db

Please sign in to comment.