C++ | O(N) | Easy Logic
Store last Odd Index and swap even number on that index when found.\n* Here lastOddIndex stores index of first odd after some even numbers in array.\n\nclass So
* Store last Odd Index and swap even number on that index when found.\n* Here `lastOddIndex` stores index of first odd after some even numbers in array.\n```\nclass Solution {class Solution {\npublic:\n    vector<int> sortArrayByParity(vector<int>& nums) {\n        \n        int n = nums.size();\n        \n        int lastOddIndex = -1;\n        \n        for(int i = 0; i < n ; i++){\n            \n            if(nums[i]%2==0 and lastOddIndex!=-1){\n                swap(nums[lastOddIndex], nums[i]);\n                lastOddIndex++;\n            }\n            \n            if(nums[i]%2!=0 and lastOddIndex==-1){\n                lastOddIndex = i;\n            }\n            \n        }\n        \n        return nums;\n        \n    }\n};\n```
['C']