简单的回溯法!

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++回溯法的更多相关文章

  1. [LeetCode][Python]17: Letter Combinations of a Phone Number

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 17: Letter Combinations of a Phone Numb ...

  2. 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 ...

  3. 刷题17. Letter Combinations of a Phone Number

    一.题目说明 题目17. Letter Combinations of a Phone Number,题目给了下面一个图,输入一个字符串包括2-9,输出所有可能的字符组合. 如输入23所有可能的输出: ...

  4. 《LeetBook》leetcode题解(17):Letter Combinations of a Phone Number[M]

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

  5. [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合

    Given a string containing digits from 2-9inclusive, return all possible letter combinations that the ...

  6. 17. Letter Combinations of a Phone Number

    题目: Given a digit string, return all possible letter combinations that the number could represent. A ...

  7. [leetcode 17]Letter Combinations of a Phone Number

    1 题目: Given a digit string, return all possible letter combinations that the number could represent. ...

  8. Java [leetcode 17]Letter Combinations of a Phone Number

    题目描述: Given a digit string, return all possible letter combinations that the number could represent. ...

  9. Leetcode 17.——Letter Combinations of a Phone Number

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

随机推荐

  1. Jenkins-pipeline

    https://my.oschina.net/ghm7753/blog/371954?p=1

  2. SVN的常用功能使用教程

    (一)导入项目到版本库中 1. 在SVN服务器的仓库中新建项目名称文件夹 2. 选择安装Visual SVN的本地计算机中的一个文件夹,右键选择导入,将本地项目导入到SVN服务中央仓库中 3. 输入在 ...

  3. css display属性

    C:内联元素加上display:block后被块级化.块级元素一般是其他元素的容器,可容纳内联元素和其他块状元素,块级元素排斥其他元素与其位于同一行,width和height起作用.因此,可以定义其宽 ...

  4. 使用axios实现上传视频进度条

    这是最终的效果图 先介绍一下axios的使用:中文的axios官方介绍 首先定义一个uploadTest方法,写在vue文件的methods里 该方法有三个参数,分别是参数,和两个回调函数,参数就是我 ...

  5. Linux系统vi或者vim编辑器中如何显示行号

    设置行号很简单 我们要到vi或者vim编辑器的命令模式下,输入set number :set number 按下回车就显示行号了 那么怎么关闭行号呢? 很简单,我们只要再到vi或者vim编辑器的命令模 ...

  6. 微信小程序 数据绑定方式

    与vue不同,在微信小程序中,js的数据和前端显示的数据是单数据流,也就是说,js里边的数据变了(通过setData),前端能立刻显示.但如果前端数据变了,js中的变量不能改变. 这个相比传统的前端已 ...

  7. Python day1_Base1笔记

    1.helloworld print('helloword') 2.输入输出 a=input('Please input a value') print(a) 3.标识符 1.由字母数字下划线构成 2 ...

  8. [转][C++]佛祖保佑,永无bug。C++ BUG解决方案

    // // _oo0oo_ // o8888888o // 88" . "88 // (| -_- |) // 0\ = /0 // ___/`---'\___ // .' \\| ...

  9. 量化投资的Python库——Tushare

    本来想用python自带的help命令和dir命令,来写一个关于Tushare库的使用手册呢,但是后来发现了Tushare的官方网站, ̄□ ̄||,网址如下: http://tushare.org/ 把 ...

  10. 第 8 章 容器网络 - 060 - 在 Docker 中使用 flannel

    在 Docker 中使用 flannel 编辑 host1 的 Docker 配置文件 /etc/systemd/system/docker.service.d/10-machine.conf 设置 ...