This is just a combination. Use Hashtable to hold the number ==> chars
Notes
1. Check corner case:input is empty, does not return vector contains empty string.
2. Mapping is a char to string. Do not use the index to string mapping
1 classSolution {2 Private:3unordered_map<Char,string>dict;4 Public:5 voidGetcomb (vector<string> &result,stringSstringCurrentintindex) {6 if(current.size () = =s.size ()) {7 Result.push_back (current);8 return;9 }Ten for(inti =0; I < dict[s[index]].size (); i++) { OneGetcomb (result, s, current + dict[s[index]][i], index+1); A } - } -vector<string> Lettercombinations (stringdigits) { thevector<string>result; - if(digits.size () = =0)returnresult; -dict['2'] ="ABC"; -dict['3'] ="def"; +dict['4'] ="Ghi"; -dict['5'] ="JKL"; +dict['6'] ="MnO"; Adict['7'] ="PQRS"; atdict['8'] ="TUV"; -dict['9'] ="WXYZ"; -Getcomb (result, digits,"",0); - returnresult; - } -};
Leetcode–refresh–letter combination of a Phone number