Java Easiest Solution || 2 Approaches Faster Than 80%Online Submission || Easy Understanding
\n//Approch :- 1 Runtime 9Ms Faster Than 33.3%\nclass Solution {\n    public int[] sortArrayByParityII(int[] nums) {\n        int even = 0,odd = 1;\n        int
```\n//Approch :- 1 Runtime 9Ms Faster Than 33.3%\nclass Solution {\n    public int[] sortArrayByParityII(int[] nums) {\n        int even = 0,odd = 1;\n        int[] arr = new int[nums.length];\n        for(int i: nums){\n            if(i%2 == 0){\n                arr[even] = i;\n                even+=2;\n            }\n            else{\n                arr[odd] = i;\n                odd+=2;\n            }\n        }\n        return arr;\n    }\n}\n\n\n//Approch :- 2 Runtime 4Ms Faster Than 77.63%\nclass Solution {\n    public int[] sortArrayByParityII(int[] nums) {\n        int even=0,odd=1;\n        int[] arr = new int[nums.length];\n        while(even<nums.length && odd<nums.length){\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(even<nums.length && odd<nums.length){\n                int temp = nums[even];\n                nums[even] = nums[odd];\n                nums[odd] = temp;\n            }\n        }\n        return nums;\n    }\n}\n```
['Java']