C++ (Simpler than Top Voted Answer)
\nclass Solution {\npublic:\n    vector<int> sortArrayByParityII(vector<int>& nums) {\n        int n = nums.size();\n        int i = 0, j = n-1;\n        //i st
```\nclass Solution {\npublic:\n    vector<int> sortArrayByParityII(vector<int>& nums) {\n        int n = nums.size();\n        int i = 0, j = n-1;\n        //i stands for even\n        //j stands for odd\n        while(i < n && j >= 0) {\n            if   (nums[i]%2 == 0)    i += 2;\n            else if(nums[j] %2 == 1) j -= 2;\n            else                     swap(nums[i], nums[j]);\n        }\n        return nums;\n    }\n};\n```
[]