Skip to content

Commit 5570976

Browse files
committed
feat: add js solution to lc problem: No.0198
1 parent 44fdf5d commit 5570976

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

solution/0100-0199/0198.House Robber/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,18 @@ function rob(nums: number[]): number {
264264
}
265265
```
266266

267+
#### JavaScript
268+
269+
```js
270+
function rob(nums) {
271+
let [f, g] = [0, 0];
272+
for (const x of nums) {
273+
[f, g] = [Math.max(f, g), f + x];
274+
}
275+
return Math.max(f, g);
276+
}
277+
```
278+
267279
<!-- tabs:end -->
268280

269281
<!-- solution:end -->

solution/0100-0199/0198.House Robber/README_EN.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,18 @@ function rob(nums: number[]): number {
263263
}
264264
```
265265

266+
#### JavaScript
267+
268+
```js
269+
function rob(nums) {
270+
let [f, g] = [0, 0];
271+
for (const x of nums) {
272+
[f, g] = [Math.max(f, g), f + x];
273+
}
274+
return Math.max(f, g);
275+
}
276+
```
277+
266278
<!-- tabs:end -->
267279

268280
<!-- solution:end -->
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function rob(nums) {
2+
let [f, g] = [0, 0];
3+
for (const x of nums) {
4+
[f, g] = [Math.max(f, g), f + x];
5+
}
6+
return Math.max(f, g);
7+
}

0 commit comments

Comments
 (0)