Given a digit string, 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.

Input:Digit string "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.

class Solution {
private:
vector<string> res;
string temp;
public:
void getRes(string digits,int len,map<char,string> num_map,int index)
{
if(index>=len)
{
res.push_back(temp);
return;
}
char strNum=digits[index];
string strLetter=num_map[strNum];
for(int j=;j<strLetter.size();j++)
{
temp.push_back(strLetter[j]);
getRes(digits,len,num_map,index+);
temp.pop_back();
} }
vector<string> letterCombinations(string digits) {
map<char,string> num_map;
num_map['']="";
num_map['']="";
num_map['']="abc";
num_map['']="def";
num_map['']="ghi";
num_map['']="jkl";
num_map['']="mno";
num_map['']="pqrs";
num_map['']="tuv";
num_map['']="wxyz";
int len=digits.size();
if(len==)
return res;
getRes(digits,len,num_map,);
return res;
}
};

Letter Combinations of a Phone Number——简单的回溯算法的更多相关文章

  1. [LeetCode]Letter Combinations of a Phone Number题解

    Letter Combinations of a Phone Number: Given a digit string, return all possible letter combinations ...

  2. [LintCode] Letter Combinations of a Phone Number 电话号码的字母组合

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  3. 69. Letter Combinations of a Phone Number

    Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations ...

  4. 【leetcode】Letter Combinations of a Phone Number

    Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations ...

  5. [LeetCode][Python]17: Letter Combinations of a Phone Number

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 17: Letter Combinations of a Phone Numb ...

  6. Letter Combinations of a Phone Number:深度优先和广度优先两种解法

    Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations ...

  7. leetcode-algorithms-17 Letter Combinations of a Phone Number

    leetcode-algorithms-17 Letter Combinations of a Phone Number Given a string containing digits from 2 ...

  8. 《LeetBook》leetcode题解(17):Letter Combinations of a Phone Number[M]

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

  9. Letter Combinations of a Phone Number - LeetCode

    目录 题目链接 注意点 解法 小结 题目链接 Letter Combinations of a Phone Number - LeetCode 注意点 可以不用按字典序排序 解法 解法一:输入的数字逐 ...

随机推荐

  1. [学习笔记]min-max容斥

    [Learning]min-max容斥以及推广 min-max容斥 就是max(a,b)=min(a)+min(b)-min(a,b) max(a,b,c)=a+b+c-min(a,b)-min(a, ...

  2. 【优先队列】【UVa11997】K Smallest Sums

    传送门 Description Input Output Translation · 给定k个长度为k的数组,把每个数组选一个元素加起来,这样共有kk种可能的答案,求最小的k个 Sample Inpu ...

  3. setTimeout()的应用

    错误写法:setTimeout(window.close(),5000); 正确写法:setTimeout(window.close,5000); 或者 setTimeout(function(){ ...

  4. Codeforces Round #345 (Div. 2) C (multiset+pair )

    C. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...

  5. FreeRTOS - configASSERT(断言)的使用

    原文地址:http://www.cnblogs.com/god-of-death/p/6891400.html  FreeRTOS中的断言函数configASSERT()和标准C中的断言函数asser ...

  6. 51Nod 1024 矩阵中不重复的元素 | 技巧 数学

    first try: set<LL> sset; int main() { LL m,n,a,b; while(~scanf("%lld%lld%lld%lld",&a ...

  7. vs 自定义插件(扩展工具)

    此篇仅仅是因为好奇,实现的是完全没有价值的东西,当然,通过此篇的尝试,后续可以在适当的场景,深入的研究Visual Studio自定义插件的应用. 实现功能如下: 在鼠标选中的地方,显示一下创建人,创 ...

  8. salt总结

    安装jdk jdk: file.managed: - source: salt://service/zabbix/files/jdk1.8.0_121.tar.gz - name: /usr/loca ...

  9. 注意for循环中变量的作用域

    for e in collections: pass 在for 循环里, 最后一个对象e一直存在在上下文中.就是在循环外面,接下来对e的引用仍然有效. 这里有个问题容易被忽略,如果在循环之前已经有一个 ...

  10. 【bzoj】1717 [Usaco2006 Dec]Milk Patterns 产奶的模式

    [算法]后缀数组 [题解]后缀数组 由于m太大,先离散化. 然后处理SA和LCP. 最后用单调队列处理即可. 注意实际上队列头尾长度限制是K-1. 删队尾不要删过头 i≥K才能开始统计答案. #inc ...