Decode XORed Permutation LeetCode solution in C++
1class Solution {2public:3vector<int> decode(vector<int> &encoded) {4int n = encoded.size(), x = 0;5// XOR of the permutation6for (int i = 1; i <= n + 1; i++) x ^= i;78// Xoring X with all the odd positioned elements to find first number9for (int i = 1; i < n; i += 2) x ^= encoded[i];1011vector<int> res;12res.push_back(x);13for (int i = 0; i < n; i++) {14x ^= encoded[i];15res.push_back(x);16}17return res;18}19};