We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dc6946f commit 719e10eCopy full SHA for 719e10e
287-find-the-duplicate-number.js
@@ -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
23
/**
24
* @param {number[]} nums
25
* @return {number}
0 commit comments