當(dāng)前位置:
首頁(yè) >
LeetCode Letter Combinations of a Phone Number 电话号码组合
發(fā)布時(shí)間:2025/4/16
37
豆豆
生活随笔
收集整理的這篇文章主要介紹了
LeetCode Letter Combinations of a Phone Number 电话号码组合
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?
?
題意:給一個(gè)電話號(hào)碼,要求返回所有在手機(jī)上按鍵的組合,組合必須由鍵盤上號(hào)碼的下方的字母組成。
思路:尼瑪,一直RE,題意都不說(shuō)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代碼?
轉(zhuǎn)載于:https://www.cnblogs.com/xcw0754/p/4677955.html
總結(jié)
以上是生活随笔為你收集整理的LeetCode Letter Combinations of a Phone Number 电话号码组合的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: [爬虫]通过url获取连接地址中的数据
- 下一篇: HDU 3973 AC's Strin