leetcode-剑指21-OK
作者:互联网
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* exchange(int* nums, int numsSize, int* returnSize){
int i = 0, j = numsSize-1;
while(i<j){
while((i<numsSize)&&(nums[i]%2==1)){
i++;
}
while((j>=0)&&(nums[j]%2==0)){
j--;
}
if(i<j){
returnSize[0] = nums[i];
nums[i] = nums[j];
nums[j] = returnSize[0];
}
}
returnSize[0] = numsSize;
return nums;
}
标签:numsSize,OK,21,nums,int,caller,leetcode,returned 来源: https://www.cnblogs.com/gallien/p/14316429.html