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

Posted shanyr

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 17. Letter Combinations of a Phone Number(水)相关的知识,希望对你有一定的参考价值。

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(水)的主要内容,如果未能解决你的问题,请参考以下文章

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

LeetCode算法题python解法:17. Letter Combinations of a Phone Number

Leetcode 17.——Letter Combinations of a Phone Number

LeetCode-17-Letter Combinations of a Phone Number

LeetCode17. Letter Combinations of a Phone Number

LeetCode17:Letter Combinations of a Phone Number