Leetcode 17
//狂练回溯,巧用备胎
class Solution {
public:
vector<string> letterCombinations(string digits) {
vector<string> res;
if(digits == "") return res;
string add;
DFS(res,add,digits,);
return res;
} void DFS(vector<string>& res,string add,string digits,int pos){
if(pos == digits.size()){
res.push_back(add);
return;
}
else{
string temp;
int t = digits[pos]-'';
if(t == ) temp = "abc";
else if(t == )temp = "def";
else if(t == )temp = "ghi";
else if(t == )temp = "jkl";
else if(t == )temp = "mno";
else if(t == )temp = "pqrs";
else if(t == )temp = "tuv";
else if(t == )temp = "wxyz";
for(int i=;i < temp.size();i++){
string beitai= add+temp[i]; //巧用备胎!!
DFS(res,beitai,digits,pos+);
}
}
}
};
Leetcode 17的更多相关文章
- [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合
Given a string containing digits from 2-9inclusive, return all possible letter combinations that the ...
- Java实现 LeetCode 17 电话号码的字母组合
17. 电话号码的字母组合 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:"23& ...
- [leetcode 17]Letter Combinations of a Phone Number
1 题目: Given a digit string, return all possible letter combinations that the number could represent. ...
- LeetCode——17. Letter Combinations of a Phone Number
一.题目链接: https://leetcode.com/problems/letter-combinations-of-a-phone-number/ 二.题目大意: 给定一段数字字符串,其中每个数 ...
- LeetCode 17 Letter Combinations of a Phone Number (电话号码字符组合)
题目链接 https://leetcode.com/problems/letter-combinations-of-a-phone-number/?tab=Description HashMap< ...
- [LeetCode] 17. 电话号码的字母组合 ☆☆☆(回溯) ###
描述 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:"23"输出:[&q ...
- 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 ...
- [LeetCode] 17. 电话号码的字母组合(回溯)
题目 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:"23" 输出:[& ...
- Java [leetcode 17]Letter Combinations of a Phone Number
题目描述: Given a digit string, return all possible letter combinations that the number could represent. ...
- Leetcode 17.——Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
随机推荐
- Django框架----Web框架本质
Web框架本质 我们可以这样理解:所有的Web应用本质上就是一个socket服务端,而用户的浏览器就是一个socket客户端. 这样我们就可以自己实现Web框架了. 半成品自定义web框架 impor ...
- sp3485推荐电路(转)
源: sp3485推荐电路 注意:转自电子发烧友 转:485通信自动收发电路 转: RS485收发的3种典型电路-重点-自动收发电路
- (七)git分支的操作
1.git branch——显示分支一览表 2.git checkout -b——创建.切换分支 往feature-A中不断add.commit叫培育分支 git checkout - 切回上一个分支 ...
- Fine报表权限流程分析记录
Fine报表权限流程分析记录 URL访问三种类型的报表:第一个:BI报表 例如: http://192.25.103.250:37799/WebReport/ReportServer?op=fr_bi ...
- 20145208 蔡野《网络对抗》shellcode注入&Return-to-libc攻击深入
20145208 蔡野<网络对抗>shellcode注入&Return-to-libc攻击深入 Shellcode注入 shellcode的获取代码 我使用了许心远同学博客中的代码 ...
- static理解
static 修饰的变量称为类变量或全局变量或成员变量,在类被加载的时候成员变量即被初始化,与类关联,只要类存在,static变量就存在. 一个static变量单独划分一块存储空间,不与具体的对象绑定 ...
- Linux下GCC生成和使用静态库和动态库【转】
本文转载自:http://www.cppblog.com/deane/articles/165216.html 一.基本概念 1.1什么是库 在windows平台和linux平台下都大量存在着库. 本 ...
- Wireshark分析RabbitMQ
消费者Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...
- 02_HBase集群部署
HBase集群部署 HBase是分布式数据库,本身也需要借助zookeeper进行集群节点间的协调(Master, RegionServer), 可以使用HBase自带的zookeeper,也可以使用 ...
- vscode中使用EF脚手架生成数据库上下文(scaffold-dbcontext)
目前在vscode上用netcore + ef core,在用dbfirst的方式生成模型和context上下文一直没有找到方法,之前在vs2017中,的nuget管理控制台输入命令: Scaffol ...