电话号码的字母组合.
b站视频.
class Solution {
public:
vector<string> res;
vector<string> v = {"", "" ,"abc", "def", "ghi", "jkl","mno","pqrs","tuv","wxyz"};
vector<string> letterCombinations(string digits) {
if(digits.empty() || digits == "") return res;
findCombinations(digits, 0, "");
return res;
}
void findCombinations(string digits, int index, string s)
{
if(index == digits.size()){
res.push_back(s);
return ;
}
string str = v[digits[index] - '0'];
for(int i = 0 ; i < str.size(); i++){
findCombinations(digits, index + 1, s + str[i]);
}
return ;
}
};