【leetcode】非递增顺序的最小子序列
int cmp(const void* a, const void* b){ return *(int*)b - *(int*)a; } int* minSubsequence(int* nums, int numsSize, int* returnSize){ qsort(nums,numsSize,sizeof(int),cmp); int i,sum=0; for (i=0; i<numsSize; i++) sum+=nums[i]; float mid = sum/2.0; for (i=0; i<numsSize; i++){ sum-=nums[i]; if (sum < mid) { *returnSize=i+1; break; } } return nums; }