标签:
class Solution { private: vector<string> res; string temp; public: void getRes(string digits,int len,map<char,string> num_map,int index) { if(index>=len) { res.push_back(temp); return; } char strNum=digits[index]; string strLetter=num_map[strNum]; for(int j=0;j<strLetter.size();j++) { temp.push_back(strLetter[j]); getRes(digits,len,num_map,index+1); temp.pop_back(); } } vector<string> letterCombinations(string digits) { map<char,string> num_map; num_map[‘0‘]=""; num_map[‘1‘]=""; num_map[‘2‘]="abc"; num_map[‘3‘]="def"; num_map[‘4‘]="ghi"; num_map[‘5‘]="jkl"; num_map[‘6‘]="mno"; num_map[‘7‘]="pqrs"; num_map[‘8‘]="tuv"; num_map[‘9‘]="wxyz"; int len=digits.size(); if(len==0) return res; getRes(digits,len,num_map,0); return res; } };
Letter Combinations of a Phone Number
标签:
原文地址:http://www.cnblogs.com/qiaozhoulin/p/4547456.html