c++ || 2 solution
\n# Code\n\nclass Solution {\npublic:\n    vector<int> sortArrayByParity(vector<int>& nums) {\n        vector<int> ans;\n        int j = nums.size() - 1;\n     
\n# Code\n```\nclass Solution {\npublic:\n    vector<int> sortArrayByParity(vector<int>& nums) {\n        vector<int> ans;\n        int j = nums.size() - 1;\n        for (int i = 0; i < nums.size(); i++) {\n            if (nums[i] % 2 == 0) {\n                ans.push_back(nums[i]);\n            }\n        }\n        for (int i = 0; i < nums.size(); i++) {\n            if (nums[i] % 2 != 0) {\n                ans.push_back(nums[i]);\n            }\n        }\n        return ans;\n    }\n};\n\n```\n# Code\n```\nclass Solution {\npublic:\n    vector<int> sortArrayByParity(vector<int>& nums) {\n        vector<int> ans(nums.size());\n        int start1=0;\n        int start2=nums.size()-1;\n        for(int i=0;i<nums.size();i++){\n            if(nums[i]%2==0){\n                ans[start1++]=nums[i];\n            }\n            else{\n           ans[start2--]=nums[i];\n            }\n        }\n        return ans;\n    }\n};\n\n```
['C++']