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

Leetcode 17. Letter Combinations of a Phone Number(水)

时间:2019-09-14 11:24:10      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:upload   app   test   div   nat   possible   mon   question   return   

17. Letter Combinations of a Phone Number
Medium

Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.

A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.

技术图片

Example:

Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].

Note:

Although the above answer is in lexicographical order, your answer could be in any order you want.

 

 1 class Solution {
 2 public:
 3     vector<string> letterCombinations(string digits) {
 4         map<char,string> test;
 5         test[2] = "abc";
 6         test[3] = "def";
 7         test[4] = "ghi";
 8         test[5] = "jkl";
 9         test[6] = "mno";
10         test[7] = "pqrs";
11         test[8] = "tuv";
12         test[9] = "wxyz";
13         vector<string> fa_;
14         vector<string> chil_;
15         fa_.push_back("");
16         for(int i = 0; i < digits.length(); i++){
17             chil_.clear();
18             for(int j = 0; j < fa_.size(); j++){
19                 //printf("%d %s",test[digits[i]].length());
20                 for(int k = 0; k < test[digits[i]].length(); k++){
21                     //printf("%s",test[digits[i]][k]);
22                     chil_.push_back(fa_[j]+test[digits[i]][k]);
23                 }
24             }
25             fa_ = chil_;
26         }
27         return chil_;
28     }
29 };

 

Leetcode 17. Letter Combinations of a Phone Number(水)

标签:upload   app   test   div   nat   possible   mon   question   return   

原文地址:https://www.cnblogs.com/shanyr/p/11518389.html

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