我宣布我已经参透了套路,一次AC
/**
* 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[10];
int visit[10]={0};
void dfs(int* nums,int numsSize,int** array,int* returnSize,int* column,int count){
if(count>numsSize) return ;
if(count==numsSize){
column[*returnSize]=count;
array[*returnSize]=(int*)malloc(sizeof(int)*count);
for(int i=0;i<count;i++) array[*returnSize][i]=temp[i];
(*returnSize)++;
return;
}
int t[21]={0};
for(int i=0;i<numsSize;i++){
if(visit[i]==0 && t[10+nums[i]]==0){
visit[i]=1;
t[10+nums[i]]=1;
temp[count]=nums[i];
dfs(nums,numsSize,array,returnSize,column,count+1);
visit[i]=0;
}
}
}
int** permuteUnique(int* nums, int numsSize, int* returnSize, int** returnColumnSizes) {
*returnSize=0;
int* column=(int*)malloc(sizeof(int)*10000);
int** array=(int**)malloc(sizeof(int*)*10000);
dfs(nums,numsSize,array,returnSize,column,0);
*returnColumnSizes=column;
return array;
}
结果:
标签:count,numsSize,排列,returnSize,int,47,IIc,array From: https://www.cnblogs.com/llllmz/p/18063359