个人主页:Lei宝啊
愿所有美好如期而遇
本题链接备战技术面试?力扣提供海量技术面试资源,帮助你高效提升编程技能,轻松拿下世界 IT 名企 Dream Offer。https://leetcode.cn/problems/letter-combinations-of-a-phone-number/submissions/
本题使用递归,该题不做解释
class Solution {
public:string str[10] = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};void Conbine(vector<string>& vs, string& digits, int di, string Cbstr){if(di == digits.size()){vs.push_back(Cbstr);return;}int num = digits[di] - '0';for(int i=0; i<str[num].size(); i++){ Conbine(vs, digits, di+1, Cbstr+str[num][i]);}}vector<string> letterCombinations(string digits) {vector<string> vs;if(digits == "")return vs;int di = 0;Conbine(vs, digits, di, "");return vs;}
};