class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param array int整型vector
* @return int整型vector
*/
vector<int> reOrderArray(vector<int>& array) {
vector<int> ret;
int len = array.size();
if (len == 0) {
return ret;
}
int oddIndex = 0, evenIndex = 0;
vector<int> oddArray(len, 0);
vector<int> evenArray(len, 0);
for (int i = 0; i < len; i++) {
// 如果是偶数,放在偶数队列中
if (array[i] % 2 == 0) {
evenArray[evenIndex++] = array[i];
} else {
oddArray[oddIndex++] = array[i];
}
}
for (int i = oddIndex, j = 0; i < len; i++, j++) {
oddArray[i] = evenArray[j];
}
return oddArray;
}
};