One Pass - Two Pointer Solution
Consider two pointers, one oddIx, pointing to odd position and the other evenIx, pointing to even position.\nBegining with oddIx at 1 and evenIx at 0, we will i
Consider two pointers, one **oddIx**, pointing to odd position and the other **evenIx**, pointing to even position.\nBegining with **oddIx at 1** and **evenIx at 0**, we will increment these **until one exceeds the length** of the array.\nIf we have odd number at even position or even number at odd position, we will like to change this, so we will **swap** only **when both**, oddIx and evenIx, **holds number of opposite category(even/odd)**.\nElse, we would simply skip the position for oddIx and evenIx if they hold number belonging to their category.\n\n\n```\nclass Solution {\n    public int[] sortArrayByParityII(int[] nums) {\n        int oddIx = 1, evenIx = 0;\n        while(oddIx < nums.length && evenIx < nums.length){\n            if (nums[oddIx] % 2 < nums[evenIx] % 2){\n                int temp = nums[oddIx];\n                nums[oddIx] = nums[evenIx];\n                nums[evenIx] = temp;\n            }\n            if (nums[oddIx] % 2 == 1)\n                oddIx = oddIx + 2;\n            if (nums[evenIx] % 2 == 0)\n                evenIx = evenIx + 2;\n        }\n        return nums;\n    }\n}\n```
['Two Pointers', 'Java']