File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
solution/0700-0799/0746.Min Cost Climbing Stairs Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,19 @@ function minCostClimbingStairs(cost: number[]): number {
152
152
}
153
153
```
154
154
155
+ #### JavaScript
156
+
157
+ ``` js
158
+ function minCostClimbingStairs (cost ) {
159
+ const n = cost .length ;
160
+ const f = Array (n + 1 ).fill (0 );
161
+ for (let i = 2 ; i <= n; ++ i) {
162
+ f[i] = Math .min (f[i - 1 ] + cost[i - 1 ], f[i - 2 ] + cost[i - 2 ]);
163
+ }
164
+ return f[n];
165
+ }
166
+ ```
167
+
155
168
#### Rust
156
169
157
170
``` rust
Original file line number Diff line number Diff line change @@ -150,6 +150,19 @@ function minCostClimbingStairs(cost: number[]): number {
150
150
}
151
151
```
152
152
153
+ #### JavaScript
154
+
155
+ ``` js
156
+ function minCostClimbingStairs (cost ) {
157
+ const n = cost .length ;
158
+ const f = Array (n + 1 ).fill (0 );
159
+ for (let i = 2 ; i <= n; ++ i) {
160
+ f[i] = Math .min (f[i - 1 ] + cost[i - 1 ], f[i - 2 ] + cost[i - 2 ]);
161
+ }
162
+ return f[n];
163
+ }
164
+ ```
165
+
153
166
#### Rust
154
167
155
168
``` rust
Original file line number Diff line number Diff line change
1
+ function minCostClimbingStairs ( cost ) {
2
+ const n = cost . length ;
3
+ const f = Array ( n + 1 ) . fill ( 0 ) ;
4
+ for ( let i = 2 ; i <= n ; ++ i ) {
5
+ f [ i ] = Math . min ( f [ i - 1 ] + cost [ i - 1 ] , f [ i - 2 ] + cost [ i - 2 ] ) ;
6
+ }
7
+ return f [ n ] ;
8
+ }
You can’t perform that action at this time.
0 commit comments