工作生活

letter-combinations-of-a-phone-n

2019-07-02  本文已影响0人  DaiMorph
class Solution {
public:
    vector<string>keyboard{" ","","abc","def","ghi",
                          "jkl","mno","pqrs","tuv","wxyz"};
    vector<string> letterCombinations(string digits) {
        vector<string>ans;
        dfs(digits,0,"",ans);
        return ans;
    }
    void dfs(string digits,int cur,string path,vector<string>&ans)
    {
        if(cur==digits.size())
        {
            ans.push_back(path);
            return;
        }
        for(auto c:keyboard[digits[cur]-'0'])
        {
            dfs(digits,cur+1,path+c,ans);
        }
    }
};
上一篇下一篇

猜你喜欢

热点阅读