【LeetCode】017. 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"].
题解:
Solution 1 ()
class Solution {
public:
void dfs(string digits, int level, vector<string>& vv, string& s, vector<string> dict){
if(level >= digits.size()) {
vv.push_back(s);
return;
}
string tmp = dict[digits[level] - ''];
for(int i=; i<tmp.size(); ++i) {
s.push_back(tmp[i]);
dfs(digits, level+, vv, s, dict);
s.pop_back();
}
}
vector<string> letterCombinations(string digits) {
if(digits.empty()) return vector<string>();
vector<string> dict = {"abc","def","ghi","jkl",
"mno","pqrs","tuv","wxyz"};
vector<string> vv;
string s;
dfs(digits, , vv, s, dict);
return vv;
}
};
【LeetCode】017. Letter Combinations of a Phone Number的更多相关文章
- 【LeetCode】17. Letter Combinations of a Phone Number 电话号码的字母组合
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:电话号码, 字母组合,回溯法,题解,leetcode, ...
- 【LeetCode】17. Letter Combinations of a Phone Number
题目: 思路:设置两个List,一个存储当前层,一个存储最终层 public class Solution { public List<String> letterCombinations ...
- 【一天一道LeetCode】#17. Letter Combinations of a Phone Number
一天一道LeetCode (一)题目 Given a digit string, return all possible letter combinations that the number cou ...
- 《LeetBook》leetcode题解(17):Letter Combinations of a Phone Number[M]
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- [LeetCode][Python]17: Letter Combinations of a Phone Number
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 17: Letter Combinations of a Phone Numb ...
- 【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 ...
- LeetCode OJ:Letter Combinations of a Phone Number(数字字母组合)
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 【LeetCode】1079. Letter Tile Possibilities 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯 日期 题目地址:https://leetcode ...
- 【LeetCode】784. Letter Case Permutation 解题报告 (Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 循环 日期 题目地址:https://leet ...
随机推荐
- Boost.Asio c++ 网络编程翻译(11)
*_at方法 这些方法在一个流上面做随机存取操作.你来指定read和write操作从什么地方開始(offset): async_read_at(stream, offset, buffer [, co ...
- Git分支中的远程操作实践
Git分支中的远程操作实践 前几篇博客陆陆续续的讲了好多关于Git操作的内容, 其中在上篇博客聊了<Git中的merge.rebase.cherry-pick以及交互式rebase>,本篇 ...
- Ubuntu下安装Oracle JRE运行环境
安装Oracle JDK -linux-i586.tar.gz安装参见在Ubuntu下利用Eclipse调试FFmpeg Linux x64:链接:http://pan.baidu.com/s/1gd ...
- file标签样式修改
1. 这是默认的file样式,无法修改,在网页中用它感觉非常不合群,大部分修改的办法就是把它隐藏,绝对定位一个文本框和一个按钮 这是修改后的样式,之后修改样式就是分别修改文本框和按钮样式了,就非常简单 ...
- css 字体的unicode码
微软雅黑: YaHei宋体: SimSun黑体: SimHei ;
- 性能测试--测试流程、APDEX、linux性能知识
测试流程.APDEX.linux性能知识 一.性能测试流程: 整体流程:收集需求-->搭建测试环境-->设计性能测试场景-->开发测试脚本-->执行测试-->收集数据-- ...
- BZOJ1815: [Shoi2006]color 有色图
BZOJ1815: [Shoi2006]color 有色图 Description Input 输入三个整数N,M,P 1< = N <= 53 1< = M < = 1000 ...
- 【iOS开发-63】Unknown type name "CGRect",did you mean "Rect"?的解决方式
出现这个问题的童鞋,差点儿都是由于用了Xcode6. 原因:在Xcode6之前,创建的文件系统会自己主动为用户导入Foundation.h和UIKit.h文件,可是最新的Xcode6仅仅为用户导入了F ...
- Redis之java增删改查
jedis是java的redis客户端实现,要使用jedis须要加入jedis的maven依赖: <dependency> <groupId>redis.clients< ...
- 【Java线程】锁机制:synchronized、Lock、Condition(转)
原文地址 1.synchronized 把代码块声明为 synchronized,有两个重要后果,通常是指该代码具有 原子性(atomicity)和 可见性(visibility). 1.1 原子性 ...