leetcode-剑指21-OK

address

/**
 * 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;
}
posted @ 2021-01-23 05:09  RougeBW  阅读(34)  评论(0编辑  收藏  举报