17. Letter Combinations of a Phone Number

Given a digit string, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below.

17. Letter Combinations of a Phone Number_第1张图片

Input:Digit string "23" Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].

class Solution {
public:
    vector v = {"","","abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    vector ans;
    char str[1000];
    //string tmp;
    
    void DFS(int cur,string &d)
    {
        if(cur == d.size())
        {
            str[d.size()] = '\0';
            string tmp = str;
            ans.push_back(tmp);
            return;
        }
        int index = d[cur] - '0';
        for(int i=0;i letterCombinations(string digits) {
        if(digits.size()<=0)
          return ans;
        ans.clear();
        DFS(0,digits);
        return ans;
    }
};

你可能感兴趣的:(17. Letter Combinations of a Phone Number)