Skip to content

Commit fd8f629

Browse files
authored
Update 1442-count-triplets-that-can-form-two-arrays-of-equal-xor.js
1 parent 56917f8 commit fd8f629

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

1442-count-triplets-that-can-form-two-arrays-of-equal-xor.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
2+
/**
3+
* @param {number[]} arr
4+
* @return {number}
5+
*/
6+
const countTriplets = function(arr) {
7+
let res = 0
8+
const n = arr.length
9+
for(let i = 0; i < n; i++) {
10+
let xor = arr[i]
11+
for(let j = i + 1; j < n; j++) {
12+
xor ^= arr[j]
13+
if(xor === 0) res += j - i
14+
}
15+
}
16+
17+
return res
18+
};
19+
20+
// another
21+
122
/**
223
* @param {number[]} arr
324
* @return {number}

0 commit comments

Comments
 (0)