SMARTEST Solution with JAVA(beats 99% / 50%) 2.way
\n\n# Code\n\nclass Solution {\n    public int[] sortArrayByParityII(int[] nums) {\n        int even = 0;\n        int odd = 1;\n\n        while(true){\n       
\n\n# Code\n```\nclass Solution {\n    public int[] sortArrayByParityII(int[] nums) {\n        int even = 0;\n        int odd = 1;\n\n        while(true){\n            while(even<nums.length && nums[even]%2 == 0){\n                even += 2;\n            }\n            while(odd<nums.length && nums[odd]%2 == 1){\n                odd += 2;\n            }\n            if(odd >= nums.length || even >= nums.length) break;\n\n            int temp = nums[odd];\n            nums[odd] = nums[even];\n            nums[even] = temp;\n        }\n        return nums;\n    }\n}\n```
['Java']