/**
* 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** subsets(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){
*returnSize=0;
*returnColumnSizes=(int*) calloc(10000, sizeof(int));
int** ans=(int**)calloc(10000,sizeof(int*));
(*returnColumnSizes)[*returnSize]=0;
*returnSize=*returnSize+1;
for(int a=0;a<numsSize;a++){
ans[*returnSize]=(int*)calloc(10,sizeof(int));
(*returnColumnSizes)[*returnSize]=1;
ans[*returnSize][0]=nums[a];
*returnSize=*returnSize+1;
int d=*returnSize;
for(int b=1;b<d-1;b++){
ans[*returnSize]=(int*)calloc(10,sizeof(int));
for(int c=0;c<(*returnColumnSizes)[b];c++){
ans[*returnSize][c]=ans[b][c];
}
ans[*returnSize][(*returnColumnSizes)[b]]=nums[a];
(*returnColumnSizes)[*returnSize]=(*returnColumnSizes)[b]+1;
*returnSize=*returnSize+1;
}
}
return ans;
}
力扣------子集
于 2022-04-26 12:11:30 首次发布