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

leetcode Letter Combinations of a Phone Number

时间:2015-04-15 00:58:16      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:

代码:

 1 #include<iostream>
 2 #include<vector>
 3 #include<string>
 4 
 5 using namespace std;
 6 
 7 vector<string> cs = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
 8 vector<string> *result = new vector<string>();
 9 
10 vector<string> F(string digits, string s)
11 {
12     int size = digits.length();
13     if (size < 1)
14         return *result;
15     if (size == 1)
16     {
17         int L = cs[digits[0] - 0].length();
18         for (int i = 0; i < L; i++)
19         {
20             string t = s;
21             t += cs[digits[0] - 0][i];
22             result->push_back(t);
23         }
24     }
25     else
26     {
27         int L = cs[digits[0] - 0].length();
28         for (int i = 0; i < L; i++)
29         {
30             string t = s;
31             t += cs[digits[0] - 0][i];
32             F(digits.substr(1), t);
33         }
34     }
35     return *result;
36 }
37 
38 vector<string> letterCombinations(string digits) {
39     return F(digits, "");
40 }
41 
42 
43 int main()
44 {
45     letterCombinations("23");
46 }

 

leetcode Letter Combinations of a Phone Number

标签:

原文地址:http://www.cnblogs.com/chaiwentao/p/4427355.html

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