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

  水题: DFS

int counts[] = {, , , , , , , , , };
char letter[] = {'', '', 'a', 'd', 'g', 'j', 'm', 'p', 't', 'w'}; class Solution {
public:
void DFS( string & digit,int i, string s)
{
if(i == size){
result.push_back(s);
return ;
}
int index = digit[i] - '' ; for(int j = ; j < counts[index] ; j++)
{ char c = letter[index]+j ; DFS(digit, i+, s+c); } }
vector<string> letterCombinations(string digits) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
result.clear();
size = digits.size(); string s = "";
DFS(digits, , s); return result ; }
private :
vector<string> result ;
int size ;
};

LeetCode_Letter Combinations of a Phone Number的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

  8. Letter Combinations of a Phone Number - LeetCode

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

  9. LeetCode: Letter Combinations of a Phone Number 解题报告

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

随机推荐

  1. 开发反模式 - SQL注入

    一.目标:编写SQL动态查询 SQL常常和程序代码一起使用.我们通常所说的SQL动态查询,是指将程序中的变量和基本SQL语句拼接成一个完整的查询语句. string sql = SELECT * FR ...

  2. 六款主流免费网络嗅探软件wireshark,tcpdump,dsniff,Ettercap,NetStumbler

    1.WireShark WireShark是一个开源免费的高性能网络协议分析软件,它的前身就是非常著名的网络分析软 件Ethereal.你可以使用它来解决网络疑难问题,进行网络协议分析,以及作为软件或 ...

  3. ECharts JavaScript图表库 ECharts

    ECharts开源来自百度商业前端数据可视化团队,基于html5 Canvas,是一个纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据可视化图表.创新的拖拽重计算.数据视图.值 ...

  4. 计算机视觉库 SimpleCV

    SimpleCV首页.文档和下载 - 计算机视觉库 - 开源中国社区     计算机视觉库 SimpleCV 编辑/纠错    分享到     新浪微博腾讯微博    已用    +0    收藏 + ...

  5. MFC调用c#的dll

    一.使用 /clr 编译 MFC 可执行文件或规则 DLL 1.打开“项目属性”对话框,方法是右键单击“解决方案资源管理器”中的项目并选择“属性”. 2.展开“配置属性”旁边的节点并选择“常规”.在右 ...

  6. systemd-journald详解

    配置文件详解 [Journal] #Storage=persistent Storage=persistent #Compress=yes #Seal=yes #SplitMode=uid #Sync ...

  7. poj 3685 Matrix(二分搜索之查找第k大的值)

    Description Given a N × N matrix A, whose element × i + j2 - × j + i × j, you are to find the M-th s ...

  8. hdu 1429 胜利大逃亡(续)(bfs+状态压缩)

    Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带 ...

  9. STS(Spring Tool Suite)使用前准备

    sts 的基础框架拿的eclipse的,你可以理解为eclipse + spring插件的高级升华版.在使用上可以很大限度的参考eclipse的操作. 首先,调整字体. 中文很麻烦的,因为编码问题.习 ...

  10. Binarized Neural Networks_ Training Neural Networks with Weights and Activations Constrained to +1 or −1

    转载请注明出处: http://www.cnblogs.com/sysuzyq/p/6248953.html by 少侠阿朱