LeetCode1310(2021.5.12)

LC1310. 子数组异或查询

class Solution {
public:
    vector<int> xorQueries(vector<int>& arr, vector<vector<int>>& queries) {
        vector<int> xors(arr.size() + 1);
        for (int i = 0; i < arr.size(); i++) xors[i + 1] = xors[i] ^ arr[i];
        vector<int> ans(queries.size());
        for (int i = 0; i < queries.size(); i++) ans[i] = xors[queries[i][0]] ^ xors[queries[i][1] + 1];
        return ans;
    }
};

发表评论