LeetCode 17. Letter Combinations of a Phone Number
Posted Travelller
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode 17. Letter Combinations of a Phone Number相关的知识,希望对你有一定的参考价值。
深搜。
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的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode算法题python解法:17. Letter Combinations of a Phone Number
Leetcode 17.——Letter Combinations of a Phone Number
LeetCode-17-Letter Combinations of a Phone Number
LeetCode17. Letter Combinations of a Phone Number