Given a digit string, return all possible letter combinations that the number could 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"].
#include
#include
#include
using namespace std;
class Solution {
public:
vector
letterCombinations(string digits) {
return letter(digits,0);
}
private:
static string strSrc[10];
vector
letter(string digits,int index) { vector
ret; if(digits.size()==0) return ret; if( index==(digits.size()-1) ) { for(int i=0;i < strSrc[ digits[index]-'0' ].size();i++) { ret.push_back( string(1,strSrc[digits[index]-'0'][i]) ); } return ret; } else { vector
tmp =letter(digits,index+1); for(int i=0;i < strSrc[ digits[index]-'0' ].size();i++) { for(int j=0;j