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 3cfe48c commit a39deffCopy full SHA for a39deff
1835-find-xor-sum-of-all-pairs-bitwise-and.js
@@ -0,0 +1,39 @@
1
+/**
2
+ * @param {number[]} arr1
3
+ * @param {number[]} arr2
4
+ * @return {number}
5
+ */
6
+const getXORSum = function(arr1, arr2) {
7
+ const bits = Array(32).fill(0)
8
+ for (let v of arr2) {
9
+ let pos = 0;
10
+ while (v > 0) {
11
+ if (v & 1) {
12
+ bits[pos]++;
13
+ }
14
+ v = v >> 1;
15
+ pos++;
16
17
18
+
19
+ let res = 0;
20
21
+ for (let v of arr1) {
22
23
+ let tmp = 0;
24
25
26
+ if (bits[pos] % 2 == 1) {
27
+ tmp |= (1 << pos);
28
29
30
31
32
33
34
+ res ^= tmp;
35
36
37
+ return res;
38
+};
39
0 commit comments