4.14
借用了一下快排的思想
public class Solution {
/**
* @param nums: an array of integers
* @return: nothing
*/
public static void partitionArray(int[] nums) {
if(nums.length <=1){
return;// write your code here;
}
int low = 0;
int height = nums.length-1;
int key = nums[low];
while(low < height){
while(low < height && nums[height]%2 == 0){
height --;
}
nums[low] = nums[height];
while(low < height && nums[low]%2 != 0){
low ++;
}
nums[height] = nums[low];
}
nums[low] = key;
}
}
转载请注明原文地址: https://ju.6miu.com/read-675605.html