Skip to content

Commit cd8966a

Browse files
committed
feat: add js solution to lc problem: No.0746
1 parent 7a53e2a commit cd8966a

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

solution/0700-0799/0746.Min Cost Climbing Stairs/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,19 @@ function minCostClimbingStairs(cost: number[]): number {
246246
}
247247
```
248248

249+
#### JavaScript
250+
251+
```js
252+
function minCostClimbingStairs(cost) {
253+
let a = 0,
254+
b = 0;
255+
for (let i = 1; i < cost.length; ++i) {
256+
[a, b] = [b, Math.min(a + cost[i - 1], b + cost[i])];
257+
}
258+
return b;
259+
}
260+
```
261+
249262
#### Rust
250263

251264
```rust

solution/0700-0799/0746.Min Cost Climbing Stairs/README_EN.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,19 @@ function minCostClimbingStairs(cost: number[]): number {
244244
}
245245
```
246246

247+
#### JavaScript
248+
249+
```js
250+
function minCostClimbingStairs(cost) {
251+
let a = 0,
252+
b = 0;
253+
for (let i = 1; i < cost.length; ++i) {
254+
[a, b] = [b, Math.min(a + cost[i - 1], b + cost[i])];
255+
}
256+
return b;
257+
}
258+
```
259+
247260
#### Rust
248261

249262
```rust
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function minCostClimbingStairs(cost) {
2+
let a = 0,
3+
b = 0;
4+
for (let i = 1; i < cost.length; ++i) {
5+
[a, b] = [b, Math.min(a + cost[i - 1], b + cost[i])];
6+
}
7+
return b;
8+
}

0 commit comments

Comments
 (0)