class Solution {
public:
vector<string>keyboard{" ","","abc","def","ghi",
"jkl","mno","pqrs","tuv","wxyz"};
vector<string> letterCombinations(string digits) {
vector<string>ans;
dfs(digits,0,"",ans);
return ans;
}
void dfs(string digits,int cur,string path,vector<string>&ans)
{
if(cur==digits.size())
{
ans.push_back(path);
return;
}
for(auto c:keyboard[digits[cur]-'0'])
{
dfs(digits,cur+1,path+c,ans);
}
}
};
网友评论