码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode 17 Letter Combinations of a Phone Number

时间:2017-02-08 23:13:50      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:com   []   ons   class   ++   ras   begin   ase   int   

class Solution {
public:
    vector<string> letterCombinations(string digits) {
        vector<string> res;
        if (digits.empty()) return res;
        string dict[] = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        res.push_back("");
        for (int i = 0; i < digits.size(); ++i) {
            int n = res.size();
            string str = dict[digits[i] - ‘2‘];
            for (int j = 0; j < n; ++j) {
                string tmp = res.front();
                res.erase(res.begin());
                for (int k = 0; k < str.size(); ++k) {
                    res.push_back(tmp + str[k]);
                }
            }
        }
        return res;
    }
};

leetcode 17 Letter Combinations of a Phone Number

标签:com   []   ons   class   ++   ras   begin   ase   int   

原文地址:http://www.cnblogs.com/wangkun1993/p/6380139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!