标签:def push ring vector length pos ber dig pre
深搜。
void DFS(int pos,string di,string temp,vector<string> &ans){ if (pos==0) {ans.push_back(temp);return;} string m[8] = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; int len=m[di[0]-‘2‘].length(); while(len--){ DFS(pos-1,di.substr(1,pos-1),temp+m[di[0]-‘2‘][len],ans); } } class Solution { public: vector<string> letterCombinations(string digits) { int len=digits.length(); if(digits.empty()) return vector<string>(); vector<string> ans; DFS(len,digits+" ","",ans); return ans; } };
LeetCode 17. Letter Combinations of a Phone Number
标签:def push ring vector length pos ber dig pre
原文地址:https://www.cnblogs.com/travelller/p/9452491.html