解题思路:
(1)需要用到数学推导,参考网址:https://leetcode.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor/discuss/623747/JavaC%2B%2BPython-One-Pass-O(N4)-to-O(N)
class Solution {
public:
int countTriplets(vector<int>& arr) {
int count=0,temp=arr[0];
int *a = new int[arr.size()+1];
for(int i=0;i<arr.size()+1;i++) {
if(i==0) a[i]=0;
else if(i==1) a[i]=arr[0];
else {
temp = temp^arr[i-1];
a[i]=temp;
}
}
for(int i=0;i<arr.size()+1;i++) {
for(int j=i+2;j<arr.size()+1;j++) {
if(a[i]==a[j])
count=count+j-i-1;
}
}
return count;
}
};