Letter combinations of a Phone number:
Given a digit string, return all possible letter combinations, the number could represent.
A mapping of Digit to letters (just as on the telephone buttons) is given below.
Input:digitstring " at"Output: ["AD","AE","af","BD"," be","BF","CD","CE","CF"].
Problem Solving Analysis:
Deep search of violence
Using vector<string> to simulate a map is easier than using a map
classSolution { Public: Vector<string> Lettercombinations (stringdigits) { Constvector<string> letter = {" ","","ABC","def","Ghi","JKL","MnO","PQRS","TUV","WXYZ"};//0,1,2 ...vector<string>result; DFS (letter, digits,0,"", result); returnresult; } voidDfsConstvector<string>& Letter,string& Digits,intCurstring Path, vector<string>&result) { if(cur = =digits.size ()) { result.push_back (path); return; } for(Auto c:letter.at (digits.at (cur)-'0') {DFS (letter, digits, cur+1,path + c, result); } }};