美文网首页工作生活
letter-combinations-of-a-phone-n

letter-combinations-of-a-phone-n

作者: DaiMorph | 来源:发表于2019-07-02 23:07 被阅读0次
    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);
            }
        }
    };
    

    相关文章

      网友评论

        本文标题:letter-combinations-of-a-phone-n

        本文链接:https://www.haomeiwen.com/subject/ooexhctx.html