1 int cmp(const void *a,const void *b) 2 { 3 return *(int*)a-*(int*)b; 4 } 5 int rangeSum(int* nums, int numsSize, int n, int left, int right){ 6 if(n<=0) return NULL; 7 int m=numsSize*(numsSize+1)/2,i,j,k; 8 int new[m]; 9 int index=0; 10 for(i=0;i<n;i++) 11 { 12 for(j=i;j<n;j++) 13 { 14 int sum=0; 15 for(k=i;k<=j;k++) 16 { 17 sum+=nums[k]; 18 } 19 new[index]=sum; 20 index++; 21 } 22 } 23 int sum1=0; 24 qsort(new,m,sizeof(int),cmp); 25 for(i=left-1;i<right;i++) 26 { 27 sum1+=new[i]; 28 } 29 return sum1%(1000000007); 30 31 32 }
标签:const,int,void,5445,数组,排序 From: https://www.cnblogs.com/sbb-first-blog/p/13289893.html