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

Leetcode 17. Letter Combinations of a Phone Number

时间:2019-05-03 09:25:25      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:com   let   app   cpp   ble   ber   push   tco   ati   

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

class Solution {
public:
    string mapping[8]={"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
    void get_string(string &digits,int l,vector<string> &ans,string &x){
        if(l==digits.size()){
            ans.push_back(x);
            return;
        }
        for(auto &e:mapping[digits[l]-'2']){
            x.push_back(e);
            get_string(digits,l+1,ans,x);
            x.pop_back();
        }
        
        
    }
    vector<string> letterCombinations(string digits) {
        /*
        注意考虑digits空的情况。
        */
        vector<string> ans;
        if(digits.empty()) return ans;
        string x;
        get_string(digits,0,ans,x);
        return ans;
    }
};

Leetcode 17. Letter Combinations of a Phone Number

标签:com   let   app   cpp   ble   ber   push   tco   ati   

原文地址:https://www.cnblogs.com/ximelon/p/10804268.html

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