奇偶分割数组
分割一个整数数组,使得奇数在前偶数在后
给定 [1, 2, 3, 4]
,返回 [1, 3, 2, 4]
。
代码示例如下
/**
* Created by jason on 2016/3/4.
*/
class Solution62 {
public void patitionArray(int[] nums) {
int apoint = 0, bpoint = nums.length-1;
if (nums != null && nums.length > 0) {
while (apoint < bpoint) {
if (nums[apoint]%2 == 0) {
int temp = nums[apoint];
nums[apoint] = nums[bpoint];
nums[bpoint] = temp;
bpoint--;
}else {
apoint++;
}
}
}
}
}