Leetcode 17. Letter Combinations of a Phone Number

Posted ximelon

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 17. Letter Combinations of a Phone Number相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode算法题python解法:17. Letter Combinations of a Phone Number

Leetcode 17.——Letter Combinations of a Phone Number

LeetCode-17-Letter Combinations of a Phone Number

LeetCode17. Letter Combinations of a Phone Number

LeetCode17:Letter Combinations of a Phone Number

[LeetCode] 17. Letter Combinations of a Phone Number