leetcode17

class Solution {

public:

    vector<string> letterCombinations(string digits) {

        

        vector<string> res;

        

        if(digits.length() == 0)

            return res;

        

        res.push_back("");

        vector<string> s = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

        

        for(int i = 0; i < digits.size(); i ++) {

            

            string num = s[digits[i] - '0'];

            vector<string> tmp;

            for(int j = 0; j < num.length(); j ++) {

                for(int k = 0; k < res.size(); k ++)

                    tmp.push_back(res[k] + num[j]);

            }

            res = tmp;

        }

        return res;

    }

};

猜你喜欢

转载自blog.csdn.net/hua111hua/article/details/83098479