1. Given a digit string, return all possible letter combinations that the number could represent.
  2.  
  3. A mapping of digit to letters (just like on the telephone buttons) is given below.

  

  1. Input:Digit string "23"
  2. Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].

  水题: DFS

  1. int counts[] = {, , , , , , , , , };
  2. char letter[] = {'', '', 'a', 'd', 'g', 'j', 'm', 'p', 't', 'w'};
  3.  
  4. class Solution {
  5. public:
  6. void DFS( string & digit,int i, string s)
  7. {
  8. if(i == size){
  9. result.push_back(s);
  10. return ;
  11. }
  12. int index = digit[i] - '' ;
  13.  
  14. for(int j = ; j < counts[index] ; j++)
  15. {
  16.  
  17. char c = letter[index]+j ;
  18.  
  19. DFS(digit, i+, s+c);
  20.  
  21. }
  22.  
  23. }
  24. vector<string> letterCombinations(string digits) {
  25. // Start typing your C/C++ solution below
  26. // DO NOT write int main() function
  27. result.clear();
  28. size = digits.size();
  29.  
  30. string s = "";
  31. DFS(digits, , s);
  32.  
  33. return result ;
  34.  
  35. }
  36. private :
  37. vector<string> result ;
  38. int size ;
  39. };

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. 在Fragment中使用BaiduMap SDK

    1:fragment_bshdzh.xml <?xml version="1.0" encoding="utf-8"?> <LinearLay ...

  2. 【Xamarin破解补丁找不到?】

    前面的博文,推荐竟然那么点数目?下面的这个网址是个各种破解资源的站点,里面说不定有你想要的. http://onhax.net/ 要学会在搜索框搜索... 好吧,其实里面就有Xamarin的破解补丁 ...

  3. 图解SSL/TLS协议(转)

    本周,CloudFlare宣布,开始提供Keyless服务,即你把网站放到它们的CDN上,不用提供自己的私钥,也能使用SSL加密链接. 我看了CloudFlare的说明(这里和这里),突然意识到这是绝 ...

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

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

  5. Calculate Number Of Islands And Lakes 解答

    Question 1 1 1 1 1 01 0 1 0 0 11 0 1 0 0 11 1 0 1 1 1 1 is earth, 0 is water. i) count the number of ...

  6. Merge Sorted Array 解答

    Question Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array ...

  7. POJ3261-哈希

    这个题让求至少出现K次的最大长度的子串,属于最大化最小值问题,首先应该想到二分求字串的长度,二分的过程是O(logN)的,注意judge的时候怎样判断是否满足情况以及满足情况后l,r的变化.可以给每一 ...

  8. Linux Top 命令

    TOP命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况. TOP是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户终止 ...

  9. 神坑 关于&&的取值

    a = 0&&"ssss": 结果a=0 a=true&&"w": 结果a=w: 类似于 前面是真的 会执行后面并返回后面 前面 ...

  10. ecshop 管理员不需要旧密码