Skip to content

Commit 77d0c7a

Browse files
authored
Update 1835-find-xor-sum-of-all-pairs-bitwise-and.js
1 parent 561f400 commit 77d0c7a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

1835-find-xor-sum-of-all-pairs-bitwise-and.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* @param {number[]} arr1
3+
* @param {number[]} arr2
4+
* @return {number}
5+
*/
6+
const getXORSum = function(arr1, arr2) {
7+
let a = 0, b = 0
8+
for(const e of arr1) a ^= e
9+
for(const e of arr2) b ^= e
10+
11+
return a & b
12+
};
13+
14+
15+
// another
16+
117
// On every bit XOR acts as modulo 2 addition and AND acts as modulo 2 multiplication.
218
// The set {0,1} with modulo 2 addition and multiplication is the field GF(2) and the distributive property holds in every field.
319

0 commit comments

Comments
 (0)