奇偶分割数组
分割一个整数数组,使得奇数在前偶数在后。
样例
给定 [1, 2, 3, 4]
,返回 [1, 3, 2, 4]
。
挑战
在原数组中完成,不使用额外空间。
public class Solution {
/*
* @param nums: an array of integers
* @return: nothing
*/
public void partitionArray(int[] nums) {
// write your code here
int a=0;
int temp=0;
for(int i=0;i<nums.length;i++){
if(nums[i]%2!=0){
temp=nums[a];
nums[a]=nums[i];
nums[i]=temp;
a++;
}
}
}
}