学习了下用qsort解决。
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int cmp(const void* a,const void* b){
return *(int*)a-*(int*)b;
}
int* sortedSquares(int* nums, int numsSize, int* returnSize) {
*returnSize=numsSize;
for(int i=0;i<numsSize;i++){
nums[i]=pow(nums[i],2);
}
qsort(nums,numsSize,sizeof(nums[0]),cmp);
return nums;
}
结果:
标签:977,numsSize,平方,const,returnSize,int,void,数组 From: https://www.cnblogs.com/llllmz/p/18036725