[JAVA] O(1) space | O(n) time | 90% faster | Easy Explained
A brief about logical approach:\n We have two poiters,\n\t i at index 0 (for even indices)\n\t j at index 1 (for odd indices)\n Now we check whether i has an ev
A brief about logical approach:\n* We have two poiters,\n\t* `i` at index 0 (for even indices)\n\t* `j` at index 1 (for odd indices)\n* Now we check whether `i` has an `even` number,\n\t* if `nums[i]` is even : `i+=2` (move to next even index)\n\t* if `nums[i]` is odd: we check whether `j` has an `odd` number,\n\t\t* if `nums[j]` is odd : `j+=2` (move to next odd index)\n\t\t* if `nums[j]` is even: swap `nums[i]` and `nums[j]`\n\nThats it!\n\nIf you found it helpful upvote. And if you have any doubts or suggestions, comment them down. \u270C\n\n\n```\nclass Solution {\n    public int[] sortArrayByParityII(int[] nums) {\n        int i=0,j=1;\n\t\t\n        while(i<nums.length && j<nums.length){\n            if(nums[i]%2==0) i+=2;\n            else{\n                if(nums[j]%2!=0) j+=2;\n                else{\n                    int temp = nums[i];\n                    nums[i]=nums[j];\n                    nums[j] = temp;\n                }\n            }\n        }\n        return nums;\n    }\n}\n```
['Java']