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. 理解class.forName()(转)

    使用jdbc方式连接数据库时会使用一句代码Class.forName(String className).这句话是什么意思呢?首先说一点Class.forName(String className)这 ...

  2. 编译不通过:提示XXXX不是类或命名空间名 的解决办法

    手动写了一个类,需要引入预编译头stdafx.h.结果编译时提示XXXX不是类或命名空间名. 处理方法:将#include "stdafx.h"放在最前面.

  3. Windows下AndroidStudio 中使用Git(AndroidStudio项目于GitHub关联)

    前提条件 : 1. 安装 Git 客户端 下载链接 2. 有 GitHub 账号 (假设你已经有了一些git基础, 如果还一点都不会, 请去找其他加成学习) AndroidStudio项目发布到Git ...

  4. 可持久化Trie树

    代码 ; struct PerTrie { ][ChSize]; ]; void init() { memset(next[],,])); inf[]=; id=; } int GetId(char ...

  5. hdu 5036 Explosion(概率期望+bitset)

    Problem Description Everyone knows Matt enjoys playing games very much. Now, he to N. Input The firs ...

  6. DoTween学习笔记(二) UGUI结合使用(实现一些简单效果)

    UGUI官方实例中是使用Animation来控制UI的移动,放大缩小动画等等, Animation来控制UI的动画工作量实在是太多了, 所以我们一般使用itween,DoTween. 来控制动画, 这 ...

  7. 浅谈NoSQL之MongoDB数据库

    对于SQL数据库(关系型数据库)我们大家都有所了解,比如MySQL,sqlserver,oracle等数据库.在日常的开发过程中我们遇到服务器端的数据存储时几乎第一反应就是使用SQL据库像我们最常见的 ...

  8. hibernate jpa 2.0 报错Hibernate cannot unwrap interface java.sql.Connection

    今天在做报表的时候,利用Hibernate JPA 2.0需要获取数据库连接com.sql.Connection的时候获取不到,网上说用这种方式解决: entityManager.getTransac ...

  9. spring aop获取目标对象的方法对象(包括方法上的注解)

    这两天在学习权限控制模块.以前看过传智播客黎活明老师的巴巴运动网视频教程,里面就讲到权限控制的解决方案,当时也只是看看视频,没有动手实践,虽说看过几遍,可是对于系统中的权限控制还是很迷茫,所以借着这次 ...

  10. Linq:切勿使用 Count() > 0 来判断集合非空

    原文(http://www.cnblogs.com/ldp615/archive/2011/12/11/2284154.html) Linq 出现之前,我们通常使用下面的方式来判断集合是否非空,即集合 ...