Sorting Is All You Need
Intuition\nDoing n&1 on n returns 1 if the least significant bit is 1, which means odd otherwise, even. Now just sort the array based on that condition.\n\n# Co
# Intuition\nDoing `n&1` on `n` returns `1` if the least significant bit is `1`, which means odd otherwise, even. Now just sort the array based on that condition.\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> sortArrayByParity(vector<int>& nums) {\n        sort(begin(nums), end(nums), [&] (int a, int b) {\n            return (a&1)<(b&1);\n        });\n        return nums;\n    }\n};\n// Please consider upvoting if the solution helped! Thank you :)\n```
['C++']