Untitled
unknown
plain_text
a month ago
567 B
6
Indexable
Never
class Solution { public: vector<int> xorQueries(vector<int>& arr, vector<vector<int>>& queries) { vector < int > ans; for(int i=1;i<arr.size();i++) { arr[i] = arr[i-1] ^ arr[i]; } for(int i=0;i<queries.size();i++) { int l = queries[i][0], r = queries[i][1]; if(l-1 < 0) { ans.push_back(arr[r]); } else { ans.push_back(arr[r] ^ arr[l-1]); } } return ans; } };
Leave a Comment