作者DJYOSHITAKA (franchouchouISBEST)
標題Re: [閒聊] 每日leetcode
時間2024-05-30 20:54:08
差不多
找subarray xor是0的 然後++
直接2D forloop嚕過去
應該可以用prefix-xor省
懶改了
def countTriplets(self, arr: List[int]) -> int:
cnt = 0
n = len(arr)
for i in range(n-1):
cur_xor = arr[i]
for j in range(i+1,n):
cur_xor = cur_xor^arr[j]
if cur_xor == 0:
cnt += (j-i)
return cnt
--
※ 發信站: 批踢踢實業坊(ptt-website.tw), 來自: 42.79.34.96 (臺灣)
※ 文章網址: https://ptt-website.tw/Marginalman/M.1717073651.A.6ED
推 Che31128: 還在卷 05/30 20:58