【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 ...
随机推荐
- SpringMVC请求流程与原理分析
SpringMVC的工作原理图: SpringMVC流程 1. 用户发送请求至前端控制器DispatcherServlet. 2. DispatcherServlet收到请求调用HandlerMa ...
- servletResponse 请求重定向
package response;/* * 重定向特点: * 1,浏览器会向服务器发送两次请求,意味着就有两个request\response * 2,用重定向技术,浏览器地址栏会发生变化 * * ...
- python中strip()函数的理解
1.strip()函数 函数原型 声明:s为字符串.rm为要删除的字符序列 s.strip(rm) :删除s字符串中开头.结尾处.位于 rm删除序列的字符 s.lstrip(rm) :删除s字符串中开 ...
- ss请cc来家里钓鱼,鱼塘可划分为n*m的格子,每个格子有不同的概率钓上鱼,cc一直在坐标(x,y)的格子钓鱼,而ss每分钟随机钓一个格子。问t分钟后他们谁至少钓到一条鱼的概率大?为多少?
include "stdafx.h" #include<iostream> #include<vector> #include<math.h> ...
- Zend API:深入 PHP 内核
Introduction Those who know don't talk. Those who talk don't know. Sometimes, PHP "as is" ...
- 在hibernate3中如何利用HQL语句查询出对象中的部分数据并且返回该对象?
例如现在有一个Customer对象 public class Customer{ private Integer cid; private String cname; private Integer ...
- Erlang节点重启导致的incarnation问题(转)
转自霸爷的博客: 转载自系统技术非业余研究 本文链接地址: Erlang节点重启导致的incarnation问题 遇到个问题, =ERROR REPORT==== 10-Mar-2016::09:44 ...
- kfaka windows安装
1 官网下载 解压到D:\developTools\kfaka\kafka_2.10-0.9.0.0 2 windows cmd启动 新开cmd命令:cd /d D:\developTools\kfa ...
- 【BZOJ4264】小C找朋友 随机化
[BZOJ4264]小C找朋友 Description 幼儿园里有N个小C,两个小C之间可能是朋友也可能不是.所有小C之间的朋友关系构成了一个无向图,这个无向图中有M条边. 园长ATM发现对于两个(不 ...
- input file 选择Excel文件 相关操作
1.HTML代码 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFo ...