[Java/C++/Python] Easy and Concise with Explantion
Intuition\nDo this first:\nGiven pref, find arr that\npref[i] = arr[0] + arr[1] + ... + arr[i]\npref is prefix sum of arr\n\nThe solution is simple:\ncpp\nfor(i
# **Intuition**\nDo this first:\nGiven `pref`, find `arr` that\n`pref[i] = arr[0] + arr[1] + ... + arr[i]`\n`pref` is prefix sum of `arr`\n\nThe solution is simple:\n```cpp\nfor(int i = A.size() - 1; i > 0; --i)\n    A[i] -= A[i - 1];\nreturn A;\n```\n\nNow we are doing something similar for this problem.\n<br>\n\n# **Explanation**\nSince `pref` is the prefix array,\nit\'s calculated from `arr` one by one,\nwe can doing this process reverssely to recover the original array.\n\nSince\n`pref[i] = pref[i-1] ^ A[i]`\nso we have\n`pref[i] ^ pref[i-1] = A[i]`\n\nSo we simply change `-` to `^` in the intuition solution\n\nThe reverse operation of `+` is `-`\nThe reverse operation of `^` is still `^`\nMore general, we can apply this solution to prefix of any operation.\n<br>\n\n# **Complexity**\nTime `O(n)`\nSpace `O(n)`\n<br>\n\n**Java**\n```java\n    public int[] findArray(int[] A) {\n        for (int i = A.length - 1; i > 0; --i)\n            A[i] ^= A[i - 1];\n        return A;\n    }\n```\n**C++**\n```cpp\n    vector<int> findArray(vector<int>& A) {\n        for (int i = A.size() - 1; i > 0; --i)\n            A[i] ^= A[i - 1];\n        return A;\n    }\n```\n**Python**\n```py\n    def findArray(self, A):\n        for i in range(len(A) - 1, 0, -1):\n            A[i] ^= A[i - 1]\n        return A\n```\n**Pythonic2**\n```py\n    def findArray(self, A):\n        return map(xor, A, [0] + A[:-1])\n```\n
['C', 'Python', 'Java']