Skip to content

Instantly share code, notes, and snippets.

@asen-ruuby
Last active November 26, 2022 10:28
Show Gist options
  • Save asen-ruuby/fae7cdb53e252435426f42f46e5ffce8 to your computer and use it in GitHub Desktop.
Save asen-ruuby/fae7cdb53e252435426f42f46e5ffce8 to your computer and use it in GitHub Desktop.
minCostClimbingStairs.js
// 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