出息了!一次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)*numsSize);
for(int i=0;i<count;i++) array[*returnSize][i]=temp[i];
(*returnSize)++;
return;
}
for(int i=0;i<numsSize;i++){
if(visit[i]==0){
temp[count]=nums[i];
visit[i]=1;
dfs(nums,numsSize,array,returnSize,column,count+1);
visit[i]=0;
}
}
}
int** permute(int* nums, int numsSize, int* returnSize, int** returnColumnSizes) {
*returnSize=0;
int** array=(int**)malloc(sizeof(int*)*10000);
int* column=(int*)malloc(sizeof(int)*10000);
dfs(nums,numsSize,array,returnSize,column,0);
*returnColumnSizes=column;
return array;
}
结果:
标签:numsSize,count,排列,returnSize,46,int,array From: https://www.cnblogs.com/llllmz/p/18063320