Skip to content

Commit 33aaa3b

Browse files
committed
feat: add js solution to lc problem: No.0137
1 parent c4ab91f commit 33aaa3b

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

solution/0100-0199/0137.Single Number II/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,21 @@ function singleNumber(nums: number[]): number {
423423
}
424424
```
425425

426+
#### JavaScript
427+
428+
```ts
429+
function singleNumber(nums) {
430+
let [ans, acc] = [0, 0];
431+
432+
for (const x of nums) {
433+
ans ^= x & ~acc;
434+
acc ^= x & ~ans;
435+
}
436+
437+
return ans;
438+
}
439+
```
440+
426441
<!-- tabs:end -->
427442

428443
<!-- solution:end -->

solution/0100-0199/0137.Single Number II/README_EN.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,21 @@ function singleNumber(nums: number[]): number {
414414
}
415415
```
416416

417+
#### JavaScript
418+
419+
```ts
420+
function singleNumber(nums) {
421+
let [ans, acc] = [0, 0];
422+
423+
for (const x of nums) {
424+
ans ^= x & ~acc;
425+
acc ^= x & ~ans;
426+
}
427+
428+
return ans;
429+
}
430+
```
431+
417432
<!-- tabs:end -->
418433

419434
<!-- solution:end -->
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function singleNumber(nums) {
2+
let [ans, acc] = [0, 0];
3+
4+
for (const x of nums) {
5+
ans ^= x & ~acc;
6+
acc ^= x & ~ans;
7+
}
8+
9+
return ans;
10+
}

0 commit comments

Comments
 (0)