/**
* 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().
*/
char c[30][30];
bool judge(char* s,int head,int tail){
if(head>tail) return false;
while(head<=tail){
if(s[head]!=s[tail]) return false;
head++;
tail--;
}
return true;
}
void dfs(char*** array,int* column,char* s,int* returnSize,int index,int count,int n){
if(index > n) return ;
if(index==n){
column[*returnSize]=count;
array[*returnSize]=(char**)malloc(sizeof(char*)*count);
for(int i=0;i<count;i++){
array[*returnSize][i]=(char*)malloc(sizeof(char)*30);
strcpy(array[*returnSize][i],c[i]);
}
(*returnSize)++;
return ;
}
for(int i=0;i<n;i++){
int tail=index+i;
if(tail >=n) continue;
if(judge(s,index,tail)){
for(int x=index;x<=tail;x++) c[count][x-index]=s[x];
dfs(array,column,s,returnSize,tail+1,count+1,n);
for(int x=index;x<=tail;x++) c[count][x-index]=0;
}
}
}
char*** partition(char* s, int* returnSize, int** returnColumnSizes) {
int n=strlen(s);
for(int i=0;i<30;i++){
for(int j=0;j<30;j++) c[i][j]=0;
}
*returnSize=0;
char*** array=(char***)malloc(sizeof(char**)*100000);
int* column=(int*)malloc(sizeof(int)*100000);
dfs(array,column,s,returnSize,0,0,n);
*returnColumnSizes=column;
return array;
}
标签:index,分割,int,tail,char,131,array,head,回文 From: https://www.cnblogs.com/llllmz/p/18088106