✔ 2 Solutions || Using Extra Space and Without Extra Space || C++
Using Extra Space : O(N) #\n\nclass Solution {\npublic:\n    vector<int> sortArrayByParityII(vector<int>& nums) {\n        \n        vector<int> odd, even;\n   
# **Using Extra Space : O(N)** #\n```\nclass Solution {\npublic:\n    vector<int> sortArrayByParityII(vector<int>& nums) {\n        \n        vector<int> odd, even;\n        for(int i = 0 ; i < nums.size(); i++)\n        {\n            if((nums[i]&1) == 1)\n                odd.push_back(nums[i]);\n            else\n                even.push_back(nums[i]);\n        }\n        int e = 0, o = 0;\n        for(int i = 0 ; i < nums.size(); i++)\n        {\n            if((i & 1) == 0){\n                nums[i] = even[e];\n                e++;\n            }\n            else\n            {\n                nums[i] = odd[o];\n                o++;\n            }\n        }\n        return nums;\n    }\n};\n```\n# **Without Using Extra Space : O(1)** #\n```\nclass Solution{\npublic:\n    vector<int> sortArrayByParityII(vector<int> &nums)\n    {\n        int i = 0, j = 1, n = nums.size();\n        while (i < n && j < n)\n        {\n            if (nums[i] % 2 == 0)\n                i += 2;\n            else if (nums[j] % 2 != 0)\n                j += 2;\n            else\n            {\n                swap(nums[i], nums[j]);\n                i += 2;\n                j += 2;\n            }\n        }\n        return nums;\n    }\n\t```
['C']