✅Easy Solution🔥Java/C++/C/Python3/Python/JavaScript🔥
\n\n\n# Code\nJava []\nclass Solution {\n    public int[] findArray(int[] pref) {\n        int[] ans = new int[pref.length];\n        ans[0] = pref[0];\n       
![LC Discuss Pic.png](https://assets.leetcode.com/users/images/73ea8fbd-329e-461c-bf5a-942dca401a7f_1698748827.5992491.png)\n\n\n# Code\n```Java []\nclass Solution {\n    public int[] findArray(int[] pref) {\n        int[] ans = new int[pref.length];\n        ans[0] = pref[0];\n        for(int i=1; i<ans.length; i++){\n            ans[i] = pref[i] ^ pref[i-1];\n        }\n        return ans;\n    }\n}\n```\n```C++ []\nclass Solution {\npublic:\n    std::vector<int> findArray(std::vector<int>& pref) {\n        std::vector<int> ans(pref.size());\n        ans[0] = pref[0];\n        for (int i = 1; i < ans.size(); i++) {\n            ans[i] = pref[i] ^ pref[i - 1];\n        }\n        return ans;\n    }\n};\n```\n```C []\nint* findArray(int* pref, int prefSize, int* returnSize){\n    int* ans = (int*)malloc(prefSize * sizeof(int));\n    ans[0] = pref[0];\n    for (int i = 1; i < prefSize; i++) {\n        ans[i] = pref[i] ^ pref[i - 1];\n    }\n    \n    *returnSize = prefSize;\n    return ans;\n}\n```\n```Python3 []\nclass Solution:\n    def findArray(self, pref: List[int]) -> List[int]:\n        ans = [0] * len(pref)\n        ans[0] = pref[0]\n        for i in range(1, len(ans)):\n            ans[i] = pref[i] ^ pref[i - 1]\n        return ans\n```\n```Python []\nclass Solution(object):\n    def findArray(self, pref):\n        ans = [0] * len(pref)\n        ans[0] = pref[0]\n        for i in range(1, len(ans)):\n            ans[i] = pref[i] ^ pref[i - 1]\n        return ans\n```\n\n```JavaScript []\n/**\n * @param {number[]} pref\n * @return {number[]}\n */\nvar findArray = function(pref) {\n    let ans = new Array(pref.length);\n    ans[0] = pref[0];\n    for (let i = 1; i < ans.length; i++) {\n        ans[i] = pref[i] ^ pref[i - 1];\n    }\n    return ans;\n};\n\n```\n
['Array', 'Math', 'Bit Manipulation', 'C', 'Prefix Sum', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']