leetcode

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

1734.cpp (415B)


      1 class Solution {
      2   public:
      3     vector<int> decode(const vector<int> &encoded) {
      4         const int n = encoded.size();
      5         vector<int> res(n + 1);
      6 
      7         res[0] = n + 1;
      8         for (int i = 0; i < n; i++) {
      9             if (i & 1) res[0] ^= encoded[i];
     10             res[0] ^= i + 1;
     11         }
     12 
     13         for (int i = 1; i <= n; i++)
     14             res[i] = res[i - 1] ^ encoded[i - 1];
     15 
     16         return res;
     17     }
     18 };