Question: Givenadigitstring, question (justlikeonthetelephonebuttons) is question: Given a digit string, return all possible letter combinations that the number cocould represent. A mapping of digit to letters (just like on the telephone buttons) is given below. input: Digit string "23" Output: ["ad", "AE", "af", "bd", "be", "bf", "cd ", "ce" , "Cf"]. The meaning of the question is to identify all possible letter combinations based on the given character sequence. First, store the letter set for the number pair and traverse all the situations with dfs.
string num[10]; char str[1000]; vector
result; void hehe(string &digits,int i,int len) { if(i==len) { str[len]='\0'; string temp=str; result.push_back(temp); return; } int index=digits[i]-'0'; for(int j=0;j
letterCombinations(string digits) { int len=digits.size(); result.clear(); num[2]="abc"; num[3]="def"; num[4]="ghi"; num[5]="jkl"; num[6]="mno"; num[7]="pqrs"; num[8]="tuv"; num[9]="wxyz"; hehe(digits,0,len); return result; } };