[Java] simple code - swap odd and even indices elements.
Use i and j to denote even and odd indices, respectively.\nLoop through input array,\n1. locate next wrongly placed item with odd index j;\n2. if current even-i
Use i and j to denote even and odd indices, respectively.\nLoop through input array,\n1. locate next wrongly placed item with odd index j;\n2. if current even-index item, A[i], is wrongly placed, swap it with A[j]; otherwise, forward to the next even index;\n\nTime: O(n), space: O(1).\n\n```\n    public int[] sortArrayByParityII(int[] A) {\n        for (int i = 0, j = 1; i < A.length; i += 2) {\n            while (j < A.length && A[j] % 2 == 1) { j += 2; } //find next odd-index item A[j] with even value.\n            if (A[i] % 2 == 1) { // if odd-index item A[i] is odd, swap it with A[j].\n                int t = A[i];\n                A[i] = A[j];\n                A[j] = t;\n                j += 2;\n            }\n        }\n        return A;\n    }\n```
[]