编程语言
首页 > 编程语言> > LeetCode题解(1310):子数组异或查询(Python)

LeetCode题解(1310):子数组异或查询(Python)

作者:互联网

题目:原题链接(中等)

标签:位运算

解法时间复杂度空间复杂度执行用时
Ans 1 (Python) O ( N ) O(N) O(N) O ( N ) O(N) O(N)516ms (10.17%)
Ans 2 (Python)
Ans 3 (Python)

解法一:

class Solution:
    def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:
        xor = [0]
        now = 0
        for num in arr:
            now ^= num
            xor.append(now)

        ans = []
        for l, r in queries:
            ans.append(xor[r + 1] ^ xor[l])
        return ans

标签:xor,1310,Python,题解,List,int,ans,now
来源: https://blog.csdn.net/Changxing_J/article/details/112858387