69. Letter Combinations of a Phone Number
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.
思路: hash && dfs.
void dfs(vector<string>& out, string ans, int curDepth, string& digits, string map[10] ){
if(curDepth == digits.length()){
out.push_back(ans);
return;
}
for(int i = 0; i < map[digits[curDepth]-'0'].length(); ++i){
ans.push_back(map[digits[curDepth]-'0'][i]);
dfs(out, ans, curDepth+1, digits, map);
ans.pop_back();
}
} class Solution {
public:
vector<string> letterCombinations(string digits) {
vector<string> out;
string ans;
string map[10] = {"", "", "abc","def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
dfs(out, ans, 0, digits, map);
return out;
}
};
69. Letter Combinations of a Phone Number的更多相关文章
- [LintCode] Letter Combinations of a Phone Number 电话号码的字母组合
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 【leetcode】Letter Combinations of a Phone Number
Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations ...
- [LeetCode][Python]17: Letter Combinations of a Phone Number
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 17: Letter Combinations of a Phone Numb ...
- Letter Combinations of a Phone Number:深度优先和广度优先两种解法
Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations ...
- leetcode-algorithms-17 Letter Combinations of a Phone Number
leetcode-algorithms-17 Letter Combinations of a Phone Number Given a string containing digits from 2 ...
- 《LeetBook》leetcode题解(17):Letter Combinations of a Phone Number[M]
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- Letter Combinations of a Phone Number - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Letter Combinations of a Phone Number - LeetCode 注意点 可以不用按字典序排序 解法 解法一:输入的数字逐 ...
- LeetCode: Letter Combinations of a Phone Number 解题报告
Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations ...
- [LeetCode]Letter Combinations of a Phone Number题解
Letter Combinations of a Phone Number: Given a digit string, return all possible letter combinations ...
随机推荐
- php max_input_vars限制数组大小
今天做一个项目需要post2000个数组过去,发现一直只能接到一半,后来发现是max_input_vars显示问题. 修改php.ini里面max_input_vars的大小就可以了
- WIN7安装及配置JDK
1:什么是JDK? JDK是Java Development Kit 的简称,即Java开发工具包.JDK是ORACLE公司针对Java开发者的产品,提供了Java的开发环境和运行环境. 更多信息参看 ...
- android 分享或者调用系统或者其他app时 应注意! startActivityForResult() 使用
//判断是否有相应的Activity来接受intentPackageManager packageManager = getPackageManager();List<ResolveInfo&g ...
- candence 知识积累4
一.PCB布局约束: 1.尺寸规划:PCB大小要合适,PCB太大印制线路长,阻抗增加.太小散热不好,易受干扰. 2.PCB尺寸确定后要确定特殊器件的位置. 3.尽可能缩短高频元器件之间的连线,设法减少 ...
- cassandra 环境搭建
1 下载安装包 http://www.planetcassandra.org/cassandra/?dlink=http://downloads.datastax.com/community/dsc- ...
- Java网络应用编程
1,网络连接 (1)用户向服务器发送请求(Socket); (2)服务器向用户发送信息(ServerSocket),一直监听的话用.accept(); 2,信息发送与接收 (1)客户向服务器端发送信息 ...
- Python 入门指南
Release: 3.4 Date: March 29, 2014 Python 是一门简单易学且功能强大的编程语言. 它拥有高效的高级数据结构,并且能够用简单而又高效的方式进行面向对象编程. Pyt ...
- Android 学习第4课,一些小知识
java语言的注释有如下3种: 1. // 2./* 注释内容 */ 3./** 注释内容 */ 这种叫文档注释,这种注释常被javaDoc文档工具读取作为 JavaDoc文 ...
- toad 9.6和toad 12.1工具使用比较
toad是我工作中使用最频繁的软件之一,阴错阳差的把2个版本都装到了电脑上,使用过程中逐渐发现2者的差异,特此做下记录,以便提示自己和其他有需要的人们.(随时更新中······)由于能力有限,难免会有 ...
- Linux下获得系统时间的C语言实现
Linux下获得系统时间的C语言的实现方法 #include<time.h> //C语言的头文件#include<stdio.h> //C语言的I/O int main() ...