import java.util.ArrayList;
public class Solution {
public static int[] reOrderArray(int[] array) {
ArrayList<Integer> oddList = new ArrayList<Integer>();
ArrayList<Integer> evenList = new ArrayList<Integer>();
for (int a : array) {
if (a % 2 == 0) {
evenList.add(a);
} else {
oddList.add(a);
}
}
oddList.addAll(evenList);
int size = oddList.size();
Integer[] inteArr = oddList.toArray(new Integer[size]);
for(int i = 0; i < size; i++) {
array[i] = inteArr[i].intValue();
}
return array;
}
}
思路是将数组分开,再合并起来。Integer转int,可以使用.intValue()。