[C++/Java] In Place Swap
Return a new array is not difficult.\nHere I shared a solution if in-place swap asked.\n\nTime Complexity:\nO(N)\n\nC++:\n\n    vector<int> sortArrayByParity(ve
Return a new array is not difficult.\nHere I shared a solution if in-place swap asked.\n\n**Time Complexity**:\nO(N)\n\n**C++:**\n```\n    vector<int> sortArrayByParity(vector<int> &A) {\n        for (int i = 0, j = 0; j < A.size(); j++)\n            if (A[j] % 2 == 0) swap(A[i++], A[j]);\n        return A;\n    }\n```\n\n**Java:**\n```\n    public int[] sortArrayByParity(int[] A) {\n        for (int i = 0, j = 0; j < A.length; j++)\n            if (A[j] % 2 == 0) {\n                int tmp = A[i];\n                A[i++] = A[j];\n                A[j] = tmp;;\n            }\n        return A;\n    }\n```
[]