1310. 子数组异或查询

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public int[] xorQueries(int[] arr, int[][] queries) {
int n = arr.length;
int[] s = new int[n+1];
for(int i = 1; i <= n; i++){
s[i] = s[i-1] ^ arr[i-1];
}
int[] ans = new int[queries.length];
for(int i = 0; i < queries.length ; i++){
int[] tmp = queries[i];
int a = tmp[0];
int b = tmp[1];
ans[i] = s[b+1] ^ s[a];
}
return ans;
}
}