/**
* Return an array of arrays of size *returnSize.
* The sizes of the arrays are returned as *returnColumnSizes array.
* Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
*/
int temp[20];
int cmp(const void* a,const void* b){
int x=*(int*)a;
int y=*(int*)b;
if(x>y) return 1;
return -1;
}
void dfs(int** array,int* column,int* nums,int numsSize,int* returnSize,int index,int count){
if(index>numsSize) return;
printf("%d\n",count);
column[*returnSize]=count;
array[*returnSize]=(int*)malloc(sizeof(int)*(count+2));
for(int i=0;i<count;i++) array[*returnSize][i]=temp[i];
(*returnSize)++;
int usu[30]={0};
for(int i=index;i<numsSize;i++){
if(usu[nums[i]+10]==0){
usu[nums[i]+10]=1;
temp[count]=nums[i];
dfs(array,column,nums,numsSize,returnSize,i+1,count+1);
}
}
}
int** subsetsWithDup(int* nums, int numsSize, int* returnSize, int** returnColumnSizes) {
qsort(nums,numsSize,sizeof(int),cmp);
int** array=(int**)malloc(sizeof(int*)*100000);
int* column=(int*)malloc(sizeof(int)*100000);
*returnSize=0;
dfs(array,column,nums,numsSize,returnSize,0,0);
*returnColumnSizes=column;
return array;
}
标签:count,return,returnSize,int,void,子集,IIc,90,array From: https://www.cnblogs.com/llllmz/p/18088232