int cmp (const void * a, const void * b){return ( *(int*)a - *(int*)b );}
int** permuteUnique(int* nums, int numsSize, int* returnSize) {
int size=1,i=0,count=1,d=1;
qsort(nums,numsSize,sizeof(int),cmp);
for(;i<numsSize-1;i++){
if(nums[i]!=nums[i+1])d++;
}
for(i=numsSize;i>1;i--)size*=i;
size=size/((numsSize>d&&d!=1)?pow(2,numsSize-d):1);
int **a=(int **)malloc(size*sizeof(int *));
int **b=(int **)malloc(size*sizeof(int *));
int **c=NULL;
for(i=0;i<size;i++)
{
a[i]=(int *)malloc((numsSize)*sizeof(int));
b[i]=(int *)malloc((numsSize)*sizeof(int));
}
for(i=0;i<numsSize;i++){//s树的层数 i
int cc=0;
for (int k=0;k<count;k++)//当前的答案数 k
{
int jishu=0;
for (int l=0;l<numsSize;l++)//nums数组中元素个数 l
{
if(jishu>0&&nums[b[cc-1][i]]==nums[l])continue;
int j=0;
for (;j<i;j++)//当前答案的节点数j
{
if (a[k][j]==l)break;
}
if (j>=i)
{
memcpy(b[cc],a[k],sizeof(int)*i);
b[cc++][i]=l;
jishu++;
}
}
}
count=cc;c=a;a=b;b=c;
}
*returnSize=count;
for(i=0;i<count;i++){
for (int j=0;j<numsSize;j++)
{
a[i][j]=nums[a[i][j]];
}
}
return a;
}