Letter Combinations of a Phone Number

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

Note:
Although the above answer is in lexicographical order, your answer could be in any order you want.

回溯法递归调用即可:

 class Solution {

 public:

     vector<string> letterCombinations(string digits) {

         vector<string> num2string();

         num2string[]="";

         num2string[] = "";  

         num2string[] = "abc";  

         num2string[] = "def";  

         num2string[] = "ghi";  

         num2string[] = "jkl";  

         num2string[] = "mno";  

         num2string[] = "pqrs";  

         num2string[] = "tuv";  

         num2string[] = "wxyz";

         vector<string> result;

         string tmp="";

         combination(digits,,tmp,num2string,result);

         return result;

     }

     void combination(string &digits,int index,string tmp,vector<string> &num2string,vector<string> &result)

     {

         if(index==digits.length())

         {

             result.push_back(tmp);

             return;

         }

         string mapString=num2string[digits[index]-''];

         for(int i=;i<mapString.length();i++)

         {

             tmp.push_back(mapString[i]);

             combination(digits,index+,tmp,num2string,result);

             tmp.pop_back();

         }

     }

 };

【leetcode】Letter Combinations of a Phone Number的更多相关文章

  1. 【leetcode】 Letter Combinations of a Phone Number(middle)

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

  2. 【Leetcode】【Medium】Letter Combinations of a Phone Number

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

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

  4. 【JAVA、C++】LeetCode 017 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】77. Combinations 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:递归 方法二:回溯法 日期 题目地址:htt ...

  7. [leetcode 17]Letter Combinations of a Phone Number

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

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

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

  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. iOS8跳到系统设置页面

    iOS5.1+之后跳转setting页面的方式都失效了,不过在iOS8苹果有提供了一个键值允许app跳转到setting页面,具体代码如下: NSURL *url = [NSURL URLWithSt ...

  2. 德州扑克AI WEB版

    继续之前的德州扑克话题,上次的DOS界面确实没法看,我女朋友说这是什么鬼.哈哈,估计只有自己能玩了 这两天重构了一下界面,基于web服务器和浏览器来交互. 服务器和客户端之间用websocket通信, ...

  3. JAVA输入一个整数,求出其所有质因数

    首先得求出能整除A的数,再判断I是否是质数!!! import java.util.*; public class aa { public static void main(String[] args ...

  4. HDU #5507 GT and Strings

    这是AC自动机系列的第一篇 传送门 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Othe ...

  5. AppStore占坑注意事项

    AppStore占坑注意事项 我们会提前在AppStore(iTunesConnect)里注册一些应用名称,以满足未来业务需要和防止恶意注册,其中有一些需要注意的事情,整理如下: 倒计时180天 为了 ...

  6. iOS动画中的枚举UIViewAnimationOptions

    若本帖转出“博客园”请注明出处(博客园·小八究):http://www.cnblogs.com/xiaobajiu/p/4084747.html 笔记 首先这个枚举属于UIViewAnimation. ...

  7. js中的全选,不选,和反选按钮的设定

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. nl命令详解

    nl命令在linux系统中用来计算文件中行号.nl 可以将输出的文件内容自动的加上行号!其默认的结果与 cat -n 有点不太一样, nl 可以将行号做比较多的显示设计,包括位数与是否自动补齐 0 等 ...

  9. memcache 缓存的批量删除方案(转)

    memcache 默认只支持使用delete(key)和 flush_all,这两种方法都太极端了,不能满足用户的特定需求,如:批量删除‘aaaaaaaa_’开头的所有缓存,这个时候该怎么办? 1 g ...

  10. iOS学习笔记—ViewController/生命周期

    ViewController是iOS应用程序中重要的部分,是应用程序数据和视图之间的重要桥梁,ViewController管理应用中的众多视图.iOS的SDK中提供很多原生ViewController ...