leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1442.cpp (447B)


0 class Solution { 1 public: 2 int countTriplets(const vector<int> &arr) { 3 static int left[301]; 4 left[0] = 0; 5 int n = arr.size(), res = 0; 6 7 for (int i = 0, acc = 0; i < n; i++) 8 left[i + 1] = acc ^= arr[i]; 9 10 for (int i = 0; i < n; i++) { 11 for (int j = i + 1; j < n; j++) { 12 if (left[i] == left[j + 1]) res += j - i; 13 } 14 } 15 16 return res; 17 } 18 };