Skip to content

Commit 719e10e

Browse files
authored
Update 287-find-the-duplicate-number.js
1 parent dc6946f commit 719e10e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

287-find-the-duplicate-number.js

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
const findDuplicate = function(nums) {
6+
let n = nums.length - 1,
7+
res = 0
8+
for (let p = 0; p < 32; ++p) {
9+
let bit = 1 << p,
10+
a = 0,
11+
b = 0
12+
for (let i = 0; i <= n; ++i) {
13+
if (i > 0 && (i & bit) > 0) ++a
14+
if ((nums[i] & bit) > 0) ++b
15+
}
16+
if (b > a) res += bit
17+
}
18+
return res
19+
}
20+
21+
// another
22+
123
/**
224
* @param {number[]} nums
325
* @return {number}

0 commit comments

Comments
 (0)