标签:ons com back return auto amp 号码 temp void
1 //DFS问题一直很难 2 class Solution 3 { 4 void dfs(string digits,vector<vector<char>>& d,vector<string> &res,int cur,string& temp) 5 { 6 if(cur == digits.size()) 7 { 8 res.push_back(temp); 9 return; 10 } 11 12 for(auto a : d[digits[cur] - ‘0‘]) 13 { 14 temp.push_back(a); 15 dfs(digits,d,res,cur + 1,temp); 16 temp.pop_back(); 17 } 18 } 19 public: 20 vector<string> letterCombinations(string digits) 21 { 22 vector<vector<char>> d(10); 23 d[0] = {‘ ‘}; 24 d[1] = {}; 25 d[2] = {‘a‘,‘b‘,‘c‘}; 26 d[3] = {‘d‘,‘e‘,‘f‘}; 27 d[4] = {‘g‘,‘h‘,‘i‘}; 28 d[5] = {‘j‘,‘k‘,‘l‘}; 29 d[6] = {‘m‘,‘n‘,‘o‘}; 30 d[7] = {‘p‘,‘q‘,‘r‘,‘s‘}; 31 d[8] = {‘t‘,‘u‘,‘v‘}; 32 d[9] = {‘w‘,‘x‘,‘y‘,‘z‘}; 33 vector<string> res; 34 if(digits.empty()) return res; 35 string temp; 36 dfs(digits,d,res,0,temp); 37 return res; 38 } 39 };
标签:ons com back return auto amp 号码 temp void
原文地址:https://www.cnblogs.com/yuhong1103/p/12499182.html