LeetCode 17. Letter Combinations of a Phone Number 时间复杂度(O( k*n))

时间复杂度(O( k*n))

 

class Solution {
public:
    vector letterCombinations(string digits) {
        
    vector result ;
    if(digits=="")return result;
    letter(digits,0,result,"");
    return result;
    }
    void letter(string digits,int digits_i,vector &result,string result_str){

        string phone_strs[] = {"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
        if(digits_i>=digits.length()){
            result.push_back(result_str);
            return ;
        }
        string currPhone = phone_strs[digits.at(digits_i)-'2'];
        for(int i=0;i

 

你可能感兴趣的:(LeetCode)