- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXOR.java
More file actions
Latest commit
25 lines (22 loc) · 626 Bytes
/
Copy pathXOR.java
File metadata and controls
25 lines (22 loc) · 626 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//Leetcode link : https://leetcode.com/problems/xor-queries-of-a-subarray/
classSolution {
publicint[] xorQueries(int[] arr, int[][] queries) {
int[] res = newint[queries.length];
inta,b,temp;
for(inti=0;i<queries.length;i++){
temp = 0;
a = queries[i][0];
b = queries[i][1];
if(a==b){
temp = arr[a];
}
else{
for(intj=a;j<=b;j++){
temp = temp ^ arr[j];
}
}
res[i] = temp;
}
returnres;
}
}