This commit is contained in:
programmercarl
2022-01-04 10:35:14 +08:00
parent a936850fb7
commit 7e3405938c
5 changed files with 59 additions and 64 deletions

View File

@@ -4,7 +4,7 @@
</a>
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
## 746. 使用最小花费爬楼梯
# 746. 使用最小花费爬楼梯
[力扣题目链接](https://leetcode-cn.com/problems/min-cost-climbing-stairs/)
@@ -181,7 +181,7 @@ public:
这么写看上去比较顺,但是就是感觉和题目描述的不太符。哈哈,也没有必要这么细扣题意了,大家只要知道,题目的意思反正就是要不是第一步不花费,要不是最后一步不花费,都可以。
# 总结
## 总结
大家可以发现这道题目相对于 昨天的[动态规划:爬楼梯](https://programmercarl.com/0070.爬楼梯.html)有难了一点,但整体思路是一样。
@@ -200,7 +200,7 @@ public:
## 其他语言版本
Java
### Java
```Java
class Solution {
public int minCostClimbingStairs(int[] cost) {
@@ -222,7 +222,7 @@ class Solution {
}
```
Python
### Python
```python
class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
@@ -234,7 +234,7 @@ class Solution:
return min(dp[len(cost) - 1], dp[len(cost) - 2])
```
Go
### Go
```Go
func minCostClimbingStairs(cost []int) int {
dp := make([]int, len(cost))
@@ -253,7 +253,7 @@ func min(a, b int) int {
}
```
Javascript
### Javascript
```Javascript
var minCostClimbingStairs = function(cost) {
const dp = [ cost[0], cost[1] ]