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