c++ o(n) solution
\n\nclass Solution {\npublic:\n    vector<int> sortArrayByParityII(vector<int>& A) {\n        int i,even=0,odd=1;\n        vector<int> B(A.size());\n        for
```\n\nclass Solution {\npublic:\n    vector<int> sortArrayByParityII(vector<int>& A) {\n        int i,even=0,odd=1;\n        vector<int> B(A.size());\n        for(i=0;i<A.size();i++)\n        {\n            if((A[i]%2)==0)\n            {\n               B[even]=A[i];\n                even+=2;\n            } \n            else\n            {\n               B[odd]=A[i];\n                odd+=2; \n            }\n        }\n        return B;\n    }\n};\n```
[]