leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1829.cpp (356B)


      1 class Solution {
      2   public:
      3     vector<int> getMaximumXor(vector<int> &nums, int maximumBit) {
      4         const int n = nums.size(), mask = (1 << maximumBit) - 1;
      5         vector<int> res(n);
      6         for (int i = 0, acc = 0; i < n; i++) {
      7             nums[i] = acc ^= nums[i];
      8             res[n - i - 1] = nums[i] ^ mask;
      9         }
     10         return res;
     11     }
     12 };