letter combination of a phone number


  • 0
    R
    class Solution {
    public:
        vector<string> res1;
        void print_recur(string digits, int ind, int len, vector<string> str, string res)
        {
            int i;
            if(ind == len-1)
            {
                for(i=0; i<str[digits.at(ind)-'0'].size();i++)
                {
                    //res = res + str[digits.at(ind)-'0'].at(i);
                    res1.push_back(res + str[digits.at(ind)-'0'].at(i));
                }
                
            }
            else
            {
                for(int i=0; i<str[digits.at(ind)-'0'].size();i++)
                {
                    //res = res + str[digits.at(ind)-'0'].at(i);
                    print_recur(digits, ind+1, len, str, res + str[digits.at(ind)-'0'].at(i));
                }
            }
            
            
        }
        vector<string> letterCombinations(string digits) {
            
            vector<string> str = {"","", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
            string res;
            int len = digits.size();
            if(len == 0)
                return res1;
            print_recur(digits, 0, len, str, res);
            return res1;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.