class Solution {
public:
map<char,string> dict; vector<string> letterCombinations(string digits) {
dict[''] = "abc";
dict[''] = "def";
dict[''] = "ghi";
dict[''] = "jkl";
dict[''] = "mno";
dict[''] = "pqrs";
dict[''] = "tuv";
dict[''] = "wxyz"; vector<string> ans;
helper(digits, digits.size(), ans); return ans;
}
// 先把前n-1个实现,然后在前面的结果中追加第n个数字对应的字母,就是最终的结果。
void helper(string &digits, int n, vector<string>& ans)
{
if(n == ) return;

     //第n个数
char num = digits[n-]; if(n == )
{
for(auto c:dict[num])//对每个字母
ans.push_back(string(,c));
return;
} //先获得前n-1个数字组成的字符串数组
        vector<string> a;
     helper(digits, n-, a);

        for(auto c: dict[num])// 把第n-1个数字,追加到每一个
{
for(auto str: a)
{
str.push_back(c);
ans.push_back(str);
}
}
}
}; 回溯就是递归。把大问题分解成小问题?不知道是怎么描述这个思想。

回溯法 17. Letter Combinations of a Phone Number的更多相关文章

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

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

  2. 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 ...

  3. 刷题17. Letter Combinations of a Phone Number

    一.题目说明 题目17. Letter Combinations of a Phone Number,题目给了下面一个图,输入一个字符串包括2-9,输出所有可能的字符组合. 如输入23所有可能的输出: ...

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

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

  5. 17. Letter Combinations of a Phone Number C++回溯法

    简单的回溯法! class Solution { public: void backTrack(string digits, vector<string> words, string an ...

  6. 【一天一道LeetCode】#17. Letter Combinations of a Phone Number

    一天一道LeetCode (一)题目 Given a digit string, return all possible letter combinations that the number cou ...

  7. 17. Letter Combinations of a Phone Number[M]电话号码的字母组合

    题目 Given a string containing digits from 2-9 inclusive, return all possible letter combinations that ...

  8. 【LeetCode】17. Letter Combinations of a Phone Number 电话号码的字母组合

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:电话号码, 字母组合,回溯法,题解,leetcode, ...

  9. Java [leetcode 17]Letter Combinations of a Phone Number

    题目描述: Given a digit string, return all possible letter combinations that the number could represent. ...

随机推荐

  1. SMD 自动点料机维修

    SMD 自动点料机维修 这个工具是一个好帮手,但是过完年回来发现坏了. 设置了数量不会自动停,按停止键没有反应,一定要按打印键才能停止. 这可愁死我了. 正常情况下开机设置好数量,然后开始点数,点到数 ...

  2. Java...点点点语法

    https://blog.csdn.net/IT_faquir/article/details/49131173

  3. RabbitMq C# .net 教程

    本文转载来自 [http://www.cnblogs.com/yangecnu/p/Introduce-RabbitMQ.html]写的很详细. 文件安装包官方DEMO下载地址是:http://pan ...

  4. update_engine-DownloadAction(一)

    通过update_engine-整体结构(一),(二),(三)对update_engine整体的运行机制有了一定的认识之后.开始逐个分析重要的Action.先从DownloadAction开始分析. ...

  5. 接口自动化 基于python+Testlink+Jenkins实现的接口自动化测试框架

    链接:http://blog.sina.com.cn/s/blog_13cc013b50102w94u.html

  6. bpmn-js起步

    https://blog.csdn.net/u013253924/article/details/85784002 通过本文逐步熟悉bpmn-js. 快速介绍: bpmn.js是一个BPMN2.0渲染 ...

  7. JavaScript 原型和对象创建底层原理

    1. prototype/__proto__/constructor JS原型链和继承网上已经烂大街了,5毛可以买一堆,这里只提一下: constructor:普通对象和函数对象都有,指向创建它的函数 ...

  8. apache 2.2 和 2.4 访问控制区别 (require 替代 deny)

    apache 2.4权限配置 Order命令已从Apache 2.4中删除 注意:使用require指令时,需要在指令外添加<RequireAll></RequireAll>标 ...

  9. Python【每日一问】12

    问:请解释线程.进程.协程 答: [定义] 进程 进程:一个运行的程序(代码)就是一个进程,进程是系统资源分配的最小单位.进程拥有自己独立的内存空间,多个进程间资源不共享 线程 线程:调度执行的最小单 ...

  10. PPIO 分布式存储在数据分发上有哪些优势?

    ​PPIO 是为开发者打造的去中心化存储与分发平台,让数据存储更便宜.更高速.更隐私.官方网站是 pp.io.PPIO 不仅仅是个存储平台,也是一个分发平台.之前我们写了许多文章介绍 PPIO 的存储 ...