LeetCode 17. Letter Combinations of a Phone Number
发布时间:2020-12-14 03:50:42 所属栏目:大数据 来源:网络整理
导读:深搜。 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
深搜。 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; } }; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |