Last active
November 26, 2022 10:28
-
-
Save asen-ruuby/fae7cdb53e252435426f42f46e5ffce8 to your computer and use it in GitHub Desktop.
minCostClimbingStairs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://leetcode.com/problems/min-cost-climbing-stairs/description/ | |
function minCostClimbingStairs(cost) { | |
const N = cost.length; | |
let [first, second] = cost; | |
for (let i = 2; i <= N; i++) { | |
[first, second] = [ | |
second, | |
(cost[i] ?? 0) + Math.min(second, first), | |
]; | |
} | |
return second; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment