/**
* Note: The returned array must be malloced, assume caller calls free().
*/
char temp[10];
char c[10][5]={" "," ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
void dfs(char** array,char* digits,int* returnSize,int n,int index,int count){
if(index>n) return ;
if(index==n){
array[*returnSize]=(char*)malloc(sizeof(char)*(count+1));
for(int i=0;i<count;i++) array[*returnSize][i]=temp[i];
array[*returnSize][count]=0;
(*returnSize)++;
return;
}
int t=digits[index]-'0';
int i=0;
while(c[t][i]!=0){
temp[count]=c[t][i++];
dfs(array,digits,returnSize,n,index+1,count+1);
}
}
char** letterCombinations(char* digits, int* returnSize) {
int n=strlen(digits);
char** array=(char**)malloc(sizeof(char*)*100000);
*returnSize=0;
dfs(array,digits,returnSize,n,0,0);
if(n==0) (*returnSize)=0;
return array;
}
标签:count,index,17,int,char,电话号码,字母组合,array From: https://www.cnblogs.com/llllmz/p/18088025