class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param array int整型vector
* @return int整型vector
*/
vector<int> reOrderArray(vector<int>& array) {
int odd_end = 0;
for(int i=0; i<array.size(); i++){
if( array[i]%2 ){ //是奇数
int temp = array[i]; //存入前面的数,把前面的偶数都往后移一位
for(int j=i; odd_end < j; j--){
array[j] = array[j-1];
}
array[odd_end] = temp;
odd_end++;
}
}
return array;
}
};

京公网安备 11010502036488号