mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Merge pull request #1791 from roylx/master
Update 0746.使用最小花费爬楼梯.md 添加Python不支付费用版本
This commit is contained in:
@ -241,6 +241,17 @@ class Solution {
|
|||||||
|
|
||||||
### Python
|
### Python
|
||||||
```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:
|
class Solution:
|
||||||
def minCostClimbingStairs(self, cost: List[int]) -> int:
|
def minCostClimbingStairs(self, cost: List[int]) -> int:
|
||||||
dp = [0] * (len(cost) + 1)
|
dp = [0] * (len(cost) + 1)
|
||||||
|
Reference in New Issue
Block a user