码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode Letter Combinations of a Phone Number 电话号码组合

时间:2015-07-26 17:05:54      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:

 

 

题意:给一个电话号码,要求返回所有在手机上按键的组合,组合必须由键盘上号码的下方的字母组成。

思路:尼玛,一直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代码

 

LeetCode Letter Combinations of a Phone Number 电话号码组合

标签:

原文地址:http://www.cnblogs.com/xcw0754/p/4677955.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!