We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 6facfc8 + 178b979 commit 7fac59cCopy full SHA for 7fac59c
1310. XOR Queries of a Subarray
@@ -0,0 +1,32 @@
1
+class Solution {
2
+public:
3
+ vector<int> xorQueries(vector<int>& arr, vector<vector<int>>& queries) {
4
+ int n = arr.size();
5
+ vector<int> ans;
6
+
7
+ vector<int> pre(n);
8
+ pre[0] = arr[0];
9
+ // cout<<pre[0]<<" ";
10
11
+ for(int i=1;i<n;i++){
12
+ pre[i] = pre[i-1] ^ arr[i];
13
+ // cout<<pre[i]<<" ";
14
+ }
15
+ // cout<<endl;
16
17
+ for(auto& val:queries){
18
+ int l = val[0];
19
+ int r = val[1];
20
21
+ if(l==0){
22
+ ans.push_back(pre[r]);
23
+ continue;
24
25
26
+ int calc = pre[r]^pre[l-1];
27
+ ans.push_back(calc);
28
29
30
+ return ans;
31
32
+};
0 commit comments