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. Slave_SQL_Running: No mysql同步故障解决方法

    Slave_SQL_Running: No mysql同步故障解决      今天检查数据库发现一台MySQL Slave未和主机同步,查看Slave状态:mysql> show slave s ...

  2. WCF 已知类型和泛型解析程序 KnownType

    数据协定继承 已知类型和泛型解析程序 Juval Lowy 下载代码示例 自首次发布以来,Windows Communication Foundation (WCF) 开发人员便必须处理数据协定继承方 ...

  3. PlayMaker 学习笔记

    1.v1.7.8.3版本无法使用全局变量,原因是Assets\Plugins\PlayMaker下的Resources文件夹变成中文了,无法创建全局变量文件,手动创建一个Resources文件夹即可

  4. Access应用日志<一>

    今天在确认实习生不能帮忙搭建数据库后,自己根据业务需求尝试搭了一个小型access数据库. 主要目的:储存历史月度数据,避免每次从公司数据库下载数据的麻烦,节省数据拉取时间. 搭建了以acct id为 ...

  5. 关于Tchar

    因为C++支持两种字符串,即常规的ANSI编码(使用""包裹)和Unicode编码(使用L""包裹),这样对应的就有了两套字符串处理函数,比如:strlen和w ...

  6. PHP基础 数组函数 的总结

    <?php /** * PHP基础 数组操作函数 * * 指针函数:[类似于数据库的游标] 见例1.1 * current($arr)/pos 返回当前指针指向的元素 * key($arr) 返 ...

  7. (:: operator)作用域限定符的几种使用

    一.(:: operator)解决局部变量与全局变量重名问题 ; int main() { ; cout<<var<<endl;//local variable cout< ...

  8. maven项目如何使用jetty启动?

    1.在pom.xml文件中插入下面的片段 <build> <plugins> <plugin> <groupId>org.eclipse.jetty&l ...

  9. iOS开发——UI基础-UIScrollView

    一.UIScrollView使用的步骤 1.创建UIScrollView 2.将需要展示的内容添加到UIScrollView中 3.设置UIScrollView的滚动范围 (contentSize) ...

  10. Android学习笔记(二十二)——短信接收与发送

    //此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 当手机接收到一条短信的时候, 系统会发出一条值为 android.provider.Telephony.SMS ...