Two Pointer Solution [Java] Optimal Space and Optimal Runtime
\nclass Solution {\n    public int[] sortArrayByParityII(int[] A) {\n        int odd = 1;\n        int even = 0;\n        \n        while (even < A.length && od
```\nclass Solution {\n    public int[] sortArrayByParityII(int[] A) {\n        int odd = 1;\n        int even = 0;\n        \n        while (even < A.length && odd < A.length){\n            while (odd < A.length && A[odd] % 2 == 1) odd +=2;\n            while (even < A.length && A[even] % 2 == 0) even += 2;\n            \n            if (even < A.length && odd < A.length){\n                swap(A, even, odd);\n                even += 2;\n                odd += 2;\n            }\n        }\n        \n        return A;\n        \n    }\n    \n    void swap(int[] A, int a, int b){\n        int temp = A[a];\n        A[a] = A[b];\n        A[b] = temp;\n    }\n    \n    \n    \n  \n}\n```
[]