首页 > 其他 > 详细

Letter Combinations of a Phone Number

时间:2015-06-02 20:07:58      阅读:119      评论:0      收藏:0      [点我收藏+]
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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!