题目描述:
思路:借用快速排序的做法,用前后两个指针。
class Solution {
public int[] exchange(int[] nums) {
int left =0;
int right=nums.length-1;
while(left<right){
while(left<right&&nums[left]%2==1){
left++;
}
while(left<right&&nums[right]%2==0){
right--;
}
if(left<right){
int tem=nums[left];
nums[left]=nums[right];
nums[right]=tem;
}
}
return nums;
}
}