17. Letter Combinations of a Phone Number

https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/

class Solution {
public:
    vector<string> lookup = { "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
    vector<string> res;
    string path;
    vector<string> letterCombinations(string digits) {
        dfs(digits, 0);
        return res;
    }
    void dfs(const string& digits, int cur) {
        if (cur == digits.length()) {
            if (!path.empty())
                res.push_back(path);
            return;
        }
        for (auto c : lookup[digits[cur]-'0']) {
            path.push_back(c);
            dfs(digits, cur+1);
            path.pop_back();
        }
    }
};
原文地址:https://www.cnblogs.com/JTechRoad/p/9055786.html