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"].

    这题其实不难,注意好递归传入的参数便可以了。
#include <vector>
#include <string>
#include <iostream>
using namespace std; class Solution {
public:
vector<string> letterCombinations(string digits) {
ret.clear();
if(digits.size()<=)
ret.push_back("");
else
help_f(,digits,"");
return ret;
}
vector<string> ret;
vector<vector<char> >mp{{' '},
{},
{'a','b','c'},
{'d','e','f'},
{'g','h','i'},
{'j','k','l'},
{'m','n','o'},
{'p','q','r','s'},
{'t','u','v'},
{'w','x','y','z'}};
void help_f(int nowIdx,string & digits,string curStr)
{
if(nowIdx==digits.size()){
ret.push_back(curStr);
return ;
}
int curNum = int(digits[nowIdx] - '');
for(int i =;i<mp[curNum].size();i++)
help_f(nowIdx+,digits,curStr+mp[curNum][i]);
}
}; int main()
{
Solution sol;
vector<string> ret=sol.letterCombinations("");
for(int i=;i<ret.size();i++)
cout<<ret[i]<<endl;
return ;
}

[LeetCode] 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. [LeetCode]Letter Combinations of a Phone Number题解

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

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

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

  4. LeetCode——Letter Combinations of a Phone Number

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

  5. [LeetCode] Letter Combinations of a Phone Number

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

  6. [LeetCode] Letter Combinations of a Phone Number(bfs)

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

  7. letter combinations of a phone number(回溯)

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

  8. LeetCode Letter Combinations of a Phone Number (DFS)

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

  9. LeetCode Letter Combinations of a Phone Number 电话号码组合

    题意:给一个电话号码,要求返回所有在手机上按键的组合,组合必须由键盘上号码的下方的字母组成. 思路:尼玛,一直RE,题意都不说0和1怎么办.DP解决. class Solution { public: ...

随机推荐

  1. mysql 查询 7天内的数据

    SELECT ID,SERVICE FROM new_schedules_spider_full WHERE SERVICE = 'WSA2' and date_sub(curdate(), inte ...

  2. 项目十八-Hadoop+Hbase分布式集群架构“完全篇”

    本文收录在Linux运维企业架构实战系列 前言:本篇博客是博主踩过无数坑,反复查阅资料,一步步搭建,操作完成后整理的个人心得,分享给大家~~~ 1.认识Hadoop和Hbase 1.1 hadoop简 ...

  3. shell与python判断文件是否存在

    日常运维中,我们会存在每日备份的现象,针对这一种情况可能会要求监控文件是否存在.比较笨拙的方法就是登录上服务器到某个路径下查看文件是否存在,除此之外,我们可以利用shell或者python来编写监控文 ...

  4. SpringBoot AOP综合例子

    完整源码:https://github.com/947133297/cgLibDemo 通过AOP来便捷地输出日志,能更加方便排查系统的bug,这个例子中简单输出自定义文件和函数执行时的参数,函数要不 ...

  5. php 单冒号 、双冒号的用法

    单冒号: 常用与三元运算,如:$result = $str ? $str : $str1; 双冒号: 1,当调用静态属性和静态方法时 2,当调用自身类或者父类的属性或者方法时

  6. Net core 轮子

    .net core 使用的人渐渐多了起来,轮子也渐渐多了起来,为了避免重复造轮子,以下列举了一些造好的轮子 1. IP 请求频率限制 git: https://github.com/stefanpro ...

  7. javascript 计算倒计时

    function timeDown(second) { var month = '', day = '', hour = '', minute = ''; if (second >= 86400 ...

  8. lnmp启用pathinfo并隐藏index.php

    编辑如下区段: location ~ [^/]\.php(/|$) { # comment try_files $uri =404; to enable pathinfo try_files $uri ...

  9. GBK UTF8 GB2132

    GBK就是在保存你的帖子的时候,一个汉字占用两个字节,外国人看会出现乱码,为此我中华为自己汉字编码而形成之解决方案. UTF8就是在保存你的帖子的时候,一个汉字占用3个字节.但是外国人看的话不会乱码. ...

  10. Redis之List类型操作

    接口: package com.net.test.redis.base.dao; import java.util.List; /** * @author *** * @Time:2017年8月10日 ...