Java two pointer one pass inplace
\n\nclass Solution {\n    public int[] sortArrayByParityII(int[] A) {\n        int i = 0, j = 1, n = A.length;\n        while (i < n && j < n) {\n            wh
```\n\nclass Solution {\n    public int[] sortArrayByParityII(int[] A) {\n        int i = 0, j = 1, n = A.length;\n        while (i < n && j < n) {\n            while (i < n && A[i] % 2 == 0) {\n                i += 2;\n            }\n            while (j < n && A[j] % 2 == 1) {\n                j += 2;\n            }\n            if (i < n && j < n) {\n                swap(A, i, j);\n            }\n        }\n        return A;\n    }\n    private void swap(int[] A, int i, int j) {\n        int temp = A[i];\n        A[i] = A[j];\n        A[j] = temp;\n    }\n}\n\n```
[]