There was an error while loading. Please reload this page.
1 parent 9c91963 commit de75b40Copy full SHA for de75b40
1435-xor-queries-of-a-subarray/xor-queries-of-a-subarray.java
@@ -0,0 +1,15 @@
1
+class Solution {
2
+ public int[] xorQueries(int[] arr, int[][] queries) {
3
+ int[] px = new int[arr.length];
4
+ int[] sol = new int[queries.length];
5
+ px[0] = arr[0];
6
+ for (int i = 1; i < arr.length; i++) {
7
+ px[i] = px[i - 1] ^ arr[i];
8
+ }
9
+
10
+ for (int i = 0; i < queries.length; i++) {
11
+ sol[i] = px[queries[i][1]] ^ px[queries[i][0]] ^ arr[queries[i][0]];
12
13
+ return sol;
14
15
+}
0 commit comments