mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Merge pull request #340 from ChrisLin1997/feature/js-746
添加0746.使用最小花费爬楼JavaScript版本
This commit is contained in:
@ -255,7 +255,18 @@ func min(a, b int) int {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Javascript:
|
||||
```Javascript
|
||||
var minCostClimbingStairs = function(cost) {
|
||||
const dp = [ cost[0], cost[1] ]
|
||||
|
||||
for (let i = 2; i < cost.length; ++i) {
|
||||
dp[i] = Math.min(dp[i -1] + cost[i], dp[i - 2] + cost[i])
|
||||
}
|
||||
|
||||
return Math.min(dp[cost.length - 1], dp[cost.length - 2])
|
||||
};
|
||||
```
|
||||
|
||||
-----------------------
|
||||
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
||||
|
Reference in New Issue
Block a user