17. Letter Combinations of a Phone Number C++回溯法
简单的回溯法!
class Solution {
public:
void backTrack(string digits, vector<string> words, string ans, vector<string>& res, int k, int flag[])
{
if(k == digits.size())
{
res.push_back(ans);
}
else
{
for(int i=; i<words[(int)(digits.at(k))-(int)''].size(); i++)
{
string t = ans;
ans.push_back(words[(int)(digits.at(k))-(int)''].at(i));
backTrack(digits,words,ans,res,k+,flag);
ans = t;//也可以直接ans.pop_back(),而不使用中间变量t
}
}
}
vector<string> letterCombinations(string digits) {
string ans;
int flag[] = {,};//0为未用过
vector<string> words = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
vector<string> res;
if(digits == "")
return res;
backTrack(digits,words,ans,res,,flag);
return res;
}
};

17. Letter Combinations of a Phone Number C++回溯法的更多相关文章
- [LeetCode][Python]17: Letter Combinations of a Phone Number
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 17: Letter Combinations of a Phone Numb ...
- 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 ...
- 刷题17. Letter Combinations of a Phone Number
一.题目说明 题目17. Letter Combinations of a Phone Number,题目给了下面一个图,输入一个字符串包括2-9,输出所有可能的字符组合. 如输入23所有可能的输出: ...
- 《LeetBook》leetcode题解(17):Letter Combinations of a Phone Number[M]
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合
Given a string containing digits from 2-9inclusive, return all possible letter combinations that the ...
- 17. Letter Combinations of a Phone Number
题目: Given a digit string, return all possible letter combinations that the number could represent. A ...
- [leetcode 17]Letter Combinations of a Phone Number
1 题目: Given a digit string, return all possible letter combinations that the number could represent. ...
- 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 ...
随机推荐
- HTTP 返回状态码说明
HTTP 返回状态码一.1xx - 信息提示 这些状态代码表示临时的响应.客户端在收到常规响应之前,应准备接收一个或多个 1xx 响应. • 100 - 继续. • 101 - 切换协议. 二.2xx ...
- 屏幕尺寸,分辨率,像素,PPI之间到底什么关系?
转载自:http://www.jianshu.com/p/c3387bcc4f6e 感谢博主的无私分享. 今天我给大家来讲讲这几个咱们经常打交道的词到底啥意思,以及他们之间到底有什么关系.这篇文章是我 ...
- win10,python3.6,django2.0.3,项目基本命令
1.django-admin startproject project_name(创建项目) 2.python manage.py startapp appname(创建应用) 3.python ma ...
- Spotlight 监控Linux服务器的性能
Spotlight功能:详细的进程跟踪功能远程连接在线的Unix/Linux的调优指南事件日志跟踪配置警报 详细的进程跟踪功能:Spotlight对具体的Unix / Linux的进程长达24小时的历 ...
- SpringBoot:Maven创建一个HelloWorld
先看一下百度百科的解释: Maven项目对象模型(POM:project object model),可以通过一小段描述信息来管理项目的构建,报告和文档的项目管理工具软件. Maven的核心功能便是合 ...
- 学习笔记37—WIN7系统本地连接没有有效的IP地址 电脑本地连接无有效ip配置怎么办
WIN7系统本地连接没有有效的IP地址 电脑本地连接无有效ip配置怎么办 家中有两台笔记本都有无线网卡,现在想让两台笔记本都能够上网,而又不想购买路由器,交换机等设备,这个时候怎么办呢? 其实只要进行 ...
- java操作vaftpd实现上传、下载
1.配置文件conf/vsftpd.properties (我是单独写了一个配置文件,你可以直接写在application中) vsftpd.ip=192.168.**.** vsftpd.user= ...
- Lua和C++交互 学习记录之六:全局函数交互
主要内容转载自:子龙山人博客(强烈建议去子龙山人博客完全学习一遍) 部分内容查阅自:<Lua 5.3 参考手册>中文版 译者 云风 制作 Kavcc vs2013+lua-5.3.3 1 ...
- zlib 2.1.8 编译遇到的问题以及解决方法
环境:win7 x64 + vs2013 1.用vs2013打开zlib-1.2.8\contrib\vstudio\vc11\zlibvc.sln进行编译 包含了下面的的多个项目: miniunz: ...
- 分享:selenium(一) xpath
xpath无所不能定位. https://www.w3.org/TR/xpath/all/#axes 两个神器:firebug.xpath-checker 举例:混合定位 //td[a//fron ...