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> lux();
lux[] = "abc"; lux[] = "def"; lux[] = "ghi"; lux[] = "jkl";
lux[] = "mno"; lux[] = "pqrs"; lux[] = "tuv"; lux[] = "wxyz"; vector<string> ans;
if(digits.empty())
{
ans.push_back("");
return ans;
} string X = digits;
vector<int> S(digits.length());
int k = ; while(k >= )
{
while(k >= && S[k] < lux[digits[k] - ''].length())
{
X[k] = lux[digits[k] - ''][S[k]++];
if(k < digits.length() - )
{
k++;
}
else
{
ans.push_back(X); //当判断条件是 (长度 - 1) 时不需要 k-- 因为最后一位数字需要循环
}
}
S[k] = ;
k--;
} if(ans.empty())
{
ans.push_back("");
return ans;
}
return ans;
}
};

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

  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】【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. 高效率http页面优化法则一【JS对DOM的操作】

    高效http页面优化法则一很多人都认为JS的效率太慢了,都不愿意用js来实现相对困难一点的程序逻辑.在这里我要说的是其实js的效率并不慢,慢的是DOM,如果操作好DOM,你的js效率将提高接近千倍(这 ...

  2. ASP.NET中gridview获取当前行的索引值

    在用GridView控件时,我们经常会碰到获取当前行的索引,通过索引进行许多操作.例如,可以获得当前行某一个控件元素:设置某一元素的值等等.下面结合实例介绍几种获得GridView当前行索引值的方法. ...

  3. 1、Java背景、标示符、运算符、转义字符

    一.Java平台: 1.Java的创建:1991年由SUN公司创建. 2.Java的特点:面向对象.可移植性.多线程.分布式.可靠.安全. 3.Java的三个架构:JavaEE.JavaSElect. ...

  4. 清北暑假模拟day1 艳阳天

    /* 注意P有可能不是质数,不要用欧拉函数那一套,正解可以倍增,就是等比数列和的性质,注意n是否为奇数 */ #include <cstdio> #include <algorith ...

  5. Ubuntu10.04下安装Ns2的一系列错误及解决方案

    安装之前改一下nam1.11下的agent.h文件73行 Null改为0 第一个错误: xxx configuration: Syntax error: Unterminated quoted str ...

  6. C语言各种标准的

    [K&R C] 1978 年,Dennis Ritchie 和 Brian Kernighan 合作推出了<The C Programming Language>的第一版(按照惯例 ...

  7. JAVA操作ORACLE数据库的存储过程

    一.任务提出 JAVA操作oracle11g存储过程实验需要完成以下几个实例: 1.调用没有返回参数的过程(插入记录.更新记录) 2.有返回参数的过程 3.返回列表的过程 4.返回带分页的列表的过程. ...

  8. redhat 中安装rpm包时遇到异常 “error: Failed dependencies:xinetd is needed by .”

    redhat 中安装rpm包时遇到错误 “error: Failed dependencies:xinetd is needed by ....” redhat中安装rpm包时遇到“error: Fa ...

  9. transition代替简单的animation注意事项

    一. transition 和 animation  不支持    Internet Explorer 9,以及更早的版本. 二. 要变化的属性 transition-property:要变化的属性, ...

  10. 演示Android百度地图操作功能

    在本文中将演示百度地图的操作功能,包括缩放,旋转,视角切换,点击,双击,长按事件触发的操作以及截图等.百度地图本来就内置有缩放,旋转功能,那么在这里,截图(其实很多手机也自带截图功能)以及点击事件的监 ...