Skip to content

Commit 89b8232

Browse files
committed
2020-06-17
1 parent aa4408f commit 89b8232

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution(object):
2+
def countTriplets(self, arr):
3+
"""
4+
:type arr: List[int]
5+
:rtype: int
6+
"""
7+
leftXOR = [0 for _ in arr] + [0]
8+
9+
res = 0
10+
11+
for i, x in enumerate(arr):
12+
leftXOR[i + 1] = leftXOR[i] ^ x
13+
14+
for i in range(len(arr) + 1):
15+
for j in range(i + 1, len(arr) + 1):
16+
for k in range(j + 1, len(arr) + 1):
17+
if leftXOR[i] ^ leftXOR[j] == leftXOR[j] ^ leftXOR[k]:
18+
res += 1
19+
20+
return res

0 commit comments

Comments
 (0)