Skip to content

Commit ad385fb

Browse files
author
baochau.dinh
committed
js-concepts: leetcode prob.746 - min cost climbing stairs
1 parent 3a2e0c9 commit ad385fb

File tree

1 file changed

+9
-0
lines changed
  • LeetCode/746. Min Cost Climbing Stairs

1 file changed

+9
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var minCostClimbingStairs = function(cost) {
2+
let fcost = [];
3+
for (let i = 0; i < cost.length; i++) {
4+
fcost[i] = cost[i] + Math.min(fcost[i - 1] || 0, fcost[i - 2] || 0);
5+
}
6+
return Math.min(fcost[fcost.length - 1], fcost[fcost.length - 2]);
7+
};
8+
9+
console.log(minCostClimbingStairs([1,100,1,1,1,100,1,1,100,1]));

0 commit comments

Comments
 (0)