/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* rearrangeArray(int* nums, int numsSize, int* returnSize){
int Positive_number[numsSize/2];
int negative[numsSize/2];
int *ans=(int*)calloc(numsSize,sizeof(int));
*returnSize=numsSize;
int b=0;
int c=0;
for(int a=0;a<numsSize;a++)
{
if(nums[a]>0){
Positive_number[b++]=nums[a];
}
else{
negative[c++]=nums[a];
}
}
b=0;
c=0;
int a=0;
while(a<numsSize){
ans[a++]=Positive_number[b++];
ans[a++]=negative[c++];
}
return ans;
}
力扣------按符号重排数组
最新推荐文章于 2024-09-03 18:29:17 发布