Skip to content

Commit

Permalink
update: finish 0746 easy
Browse files Browse the repository at this point in the history
  • Loading branch information
benben6515 committed Jul 18, 2022
1 parent 9e5509c commit a435315
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Leet code

https://leetcode.com/z2266109/
<https://leetcode.com/z2266109/>

![Leetcode Stats](https://leetcode.card.workers.dev/?username=z2266109&theme=unicorn&extension=activity)

Expand Down Expand Up @@ -50,6 +50,7 @@ since 2021.10.10 / Benben
- 0572.Subtree of Another Tree
- 0703.Kth Largest Element in a Stream
- 0704.Binary Search
- 0764.Min Cost Climbing Stairs
- 0905.Sort Array By Parity
- 1046.Last Stone Weight
- 1694.Reformat Phone Number
Expand Down
18 changes: 18 additions & 0 deletions leetcode-easy/0746-min-cost-climbing-stairs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @param {number[]} cost
* @return {number}
*/
var minCostClimbingStairs = function(cost) {
if (cost.length < 3) Math.min(cost[0], cost[1])

cost.push(0)
for (let i = cost.length - 3; i > -1; i--) {
cost[i] = cost[i] + Math.min(cost[i + 1], cost[i + 2])
}

return Math.min(cost[0], cost[1])
};

// 2022/07/18 done.
// Runtime: 110 ms, faster than 31.22% of JavaScript online submissions for Min Cost Climbing Stairs.
// Memory Usage: 44.3 MB, less than 29.22% of JavaScript online submissions for Min Cost Climbing Stairs.

0 comments on commit a435315

Please sign in to comment.