LeetCode Letter Combinations of a Phone Number 电话号码组合
生活随笔
收集整理的這篇文章主要介紹了
LeetCode Letter Combinations of a Phone Number 电话号码组合
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
?
題意:給一個電話號碼,要求返回所有在手機上按鍵的組合,組合必須由鍵盤上號碼的下方的字母組成。
思路:尼瑪,一直RE,題意都不說0和1怎么辦。DP解決。
?
?
1 class Solution { 2 public: 3 vector<string> ans; 4 string str; 5 6 void DFS(const string sett[], int siz, string t ) 7 { 8 int n=str[siz]-'0'; 9 if(siz==str.size()){ans.push_back( t );return ;} 10 for(int i=0; i<sett[n].size(); i++) DFS(sett, siz+1, t+sett[n][i] ); 11 } 12 13 vector<string> letterCombinations(string digits) { 14 if(digits.empty()) return vector<string> (); 15 str=digits; 16 const string mapp[]={"0","1","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; 17 DFS(mapp, 0, ""); 18 return ans; 19 } 20 }; AC代碼?
轉載于:https://www.cnblogs.com/xcw0754/p/4677955.html
總結
以上是生活随笔為你收集整理的LeetCode Letter Combinations of a Phone Number 电话号码组合的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [爬虫]通过url获取连接地址中的数据
- 下一篇: HDU 3973 AC's Strin