题解 | #调整数组顺序使奇数位于偶数前面#
调整数组顺序使奇数位于偶数前面
https://www.nowcoder.com/practice/beb5aa231adc45b2a5dcc5b62c93f593
class Solution { public: void reOrderArray(vector<int>& array) { vector<int>v(array.size(), 0); int low = 0; for (int i = 0; i < array.size(); i++) { if ((array[i] & 1) == 1) { v[low++] = array[i]; } } for (int i = 0; i < array.size(); i++) { if ((array[i] & 1) == 0) { v[low++] = array[i]; } } array.assign(v.begin(), v.end()); } };