Skip to content

Commit 18ef5e3

Browse files
committed
feat: add js solution to lc problem: No.0137
1 parent ac03d70 commit 18ef5e3

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,19 @@ function singleNumber(nums: number[]): number {
146146
}
147147
```
148148

149+
#### JavaScript
150+
151+
```js
152+
function singleNumber(nums) {
153+
let ans = 0;
154+
for (let i = 0; i < 32; i++) {
155+
const count = nums.reduce((r, v) => r + ((v >> i) & 1), 0);
156+
ans |= count % 3 << i;
157+
}
158+
return ans;
159+
}
160+
```
161+
149162
#### Rust
150163

151164
```rust

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,19 @@ function singleNumber(nums: number[]): number {
137137
}
138138
```
139139

140+
#### JavaScript
141+
142+
```js
143+
function singleNumber(nums) {
144+
let ans = 0;
145+
for (let i = 0; i < 32; i++) {
146+
const count = nums.reduce((r, v) => r + ((v >> i) & 1), 0);
147+
ans |= count % 3 << i;
148+
}
149+
return ans;
150+
}
151+
```
152+
140153
#### Rust
141154

142155
```rust
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function singleNumber(nums) {
2+
let ans = 0;
3+
for (let i = 0; i < 32; i++) {
4+
const count = nums.reduce((r, v) => r + ((v >> i) & 1), 0);
5+
ans |= count % 3 << i;
6+
}
7+
return ans;
8+
}

0 commit comments

Comments
 (0)