/**
* 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){
return *(int*)a-*(int*)b;
}
void dfs(int** array,int* nums,int numsSize,int* returnSize,int* column,int index,int count){
if(index>numsSize) return;
column[*returnSize]=count;
array[*returnSize]=(int*)malloc(sizeof(int)*count);
for(int i=0;i<count;i++) array[*returnSize][i]=temp[i];
(*returnSize)++;
if(index==numsSize) return;
int use[30]={0};
for(int i=index;i<numsSize;i++){
if(use[nums[i]+10]==0){
use[nums[i]+10]=1;
temp[count]=nums[i];
dfs(array,nums,numsSize,returnSize,column,i+1,count+1);
}
}
}
int** subsetsWithDup(int* nums, int numsSize, int* returnSize, int** returnColumnSizes) {
(*returnSize)=0;
qsort(nums,numsSize,sizeof(int),cmp);
int* column=(int*)malloc(sizeof(int)*25000);
int** array=(int**)malloc(sizeof(int*)*25000);
dfs(array,nums,numsSize,returnSize,column,0,0);
*returnColumnSizes=column;
return array;
}
结果:
标签:count,numsSize,returnSize,int,void,子集,IIC,90,array From: https://www.cnblogs.com/llllmz/p/18076980