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. 30秒搭建Github Page

    如果中国每个程序员都写博客,那么中国IT届的春天就来了 原文转自我的前端博客,链接:http://www.hacke2.cn/create-github-page/ 有同学问我的网站是怎么创建的,其实 ...

  2. winform 开发心得~

    winform自适应不同分辨率 不同dpi 1.窗体AutoScaleMode属性 使用None 2.自定义控件 AutoScaleMode 使用Inherit 3.所有控件窗体字体使用px为单位

  3. seo是什么职业

    SEO(Search Engine Optimization)汉译为搜索引擎优化.seo从业者首要工作就是优化网站,使其符合搜索引擎的基本规律和满足用户的需求,进而获得大量的用户访问.SEO职业属于一 ...

  4. js跳转页面

    <script type="text/javascript">  方法一: location.href = 'http://www.baidu.com'; 方法二: l ...

  5. 【python网络编程】使用rsa加密算法模块模拟登录新浪微博

    一.基础知识 http://blog.csdn.net/pi9nc/article/details/9734437 二.模拟登录 因为上学期参加了一个大数据比赛,需要抓取数据,所以就想着写个爬虫抓取新 ...

  6. xcode 插件

    http://www.cocoachina.com/ios/20160122/15080.html https://github.com/rickytan/RTImageAssets http://m ...

  7. Sql统计一个字符串在另一个字符串出现的次数的函数-fnQueryCharCountFromString

    SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ),)) returns int as begin declare @pos int,@n int , ...

  8. 01Getting Started---Getting Started with ASP.NET Web API 2入门WebApi2

    HTTP 不只是为了生成 web 页面.它也是建立公开服务和数据的 Api 的强大平台.HTTP 是简单的. 灵活的和无处不在.你能想到的几乎任何平台有 HTTP 库,因此,HTTP 服务可以达到范围 ...

  9. 实操UNITY3D接入91SDK安卓版

    原地址:http://bbs.18183.com/thread-149758-1-1.html 本文内容为创建UNITY3D接入91SDK的DEMO的具体操作过程.本人水平有限,UNITY3D与And ...

  10. HackerRank savita-and-friends

    Description 在一条边上求一个点,使得这个点到所有点的最长的最短距离 最短. \(n \leqslant 10^5\) Sol Dijkstra+扫描线+单调队列. 这个好像叫什么最小直径生 ...