Leetcode 17. 电话号码的字母组合

class Solution {
public:
    const string letterMap[10] = {
            "", // 0
            "", // 1
            "abc", // 2
            "def", // 3
            "ghi", // 4
            "jkl", // 5
            "mno", // 6
            "pqrs", // 7
            "tuv", // 8
            "wxyz", // 9
        };
    vector<string> res;
    string s;
    void backtrace(const string &index,int depth)
    {
        if(depth == index.length())
        {
            res.push_back(s);
            return;
        }
        int add = index[depth] - '0';
        string letters = letterMap[add];
        for(int i = 0; i < letters.length(); i++)
        {
            s.push_back(letters[i]);
            backtrace(index, depth+1);
            s.pop_back();
        }
    }
    vector<string> letterCombinations(string digits) {
        int len = digits.length();
        s.clear();
        res.clear();
        if(len == 0)
        {
            return res;
        }
        backtrace(digits,0);
        return res;
        
    }
};