【每日一题】
作者:互联网
https://leetcode-cn.com/problems/xor-queries-of-a-subarray/
缓存一下
class Solution {
public int[] xorQueries(int[] arr, int[][] queries) {
int n = arr.length;
int[] xors = new int[n + 1];
for (int i = 0; i < n; i++) {
xors[i + 1] = xors[i] ^ arr[i];
}
int m = queries.length;
int[] ans = new int[m];
for (int i = 0; i < m; i++) {
ans[i] = xors[queries[i][0]] ^ xors[queries[i][1] + 1];
}
return ans;
}
}
标签:xors,int,每日,queries,arr,ans,new 来源: https://www.cnblogs.com/realzhaijiayu/p/14759405.html