DLC May, Day 2 | C++ | 2 pointer approach | Easy O(N) solution
Approach-1:\n\n\nclass Solution {\npublic:\n    vector<int> sortArrayByParity(vector<int>& nums) \n    {\n        for(int i=0, j=0; j<nums.size(); j++)\n       
**Approach-1:**\n\n```\nclass Solution {\npublic:\n    vector<int> sortArrayByParity(vector<int>& nums) \n    {\n        for(int i=0, j=0; j<nums.size(); j++)\n        {\n            if(nums[j]%2 == 0) swap(nums[i++], nums[j]);\n        }\n        return nums;\n    }\n};\n```\n\n**Approach-2:**\n```\nclass Solution {\npublic:\n    vector<int> sortArrayByParity(vector<int>& nums) \n    {\n        int even=nums.size()-1, odd=0;\n        while(odd<even)\n        {\n            if(nums[even]%2==0)\n            {\n                swap(nums[odd], nums[even]);\n                odd++;\n            }\n            \n            if(nums[even]%2==1)\n                even--;               \n        }\n        return nums;\n        \n    }\n};\n```\n\n\n
['Two Pointers', 'C', 'C++']