letter-combinations-of-a-phone-number

class Solution {
public:
    vectorkeyboard{" ","","abc","def","ghi",
                          "jkl","mno","pqrs","tuv","wxyz"};
    vector letterCombinations(string digits) {
        vectorans;
        dfs(digits,0,"",ans);
        return ans;
    }
    void dfs(string digits,int cur,string path,vector&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-number)