原题地址

 

简单DFS题目

 

代码:

 1 vector<string> res;
 2     
 3 void dfs(string &digits, vector<string> &i2s, string ans, int pos) {
 4   if (pos == digits.length()) {
 5     res.push_back(ans);
 6     return;
 7   }
 8         
 9   for (auto c : i2s[digits[pos] - '0'])
10     dfs(digits, i2s, ans + c, pos + 1);
11 }
12 
13 vector<string> letterCombinations(string digits) {
14   vector<string> i2s {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
15   dfs(digits, i2s, "", 0);
16   return res;
17 }

 

相关文章:

  • 2021-07-30
  • 2022-02-20
  • 2022-01-28
  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-11
  • 2021-06-09
  • 2021-06-12
  • 2022-02-04
  • 2021-06-21
  • 2022-02-01
  • 2021-08-07
  • 2021-10-07
相关资源
相似解决方案