简单的回溯法!

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. 2、Python函数详解(0601)

    函数的基础概念 1.函数是python为了代码最大程度的重用和最小化代码冗余而提供的基本程序结构: 2.函数是一种设计工具,它能让程序员将复杂的系统分解为可管理的部件: 3.函数用于将相关功能打包并参 ...

  2. JavaScript运行机制详解

    JavaScript运行机制详解   var test = function(){ alert("test"); } var test2 = function(){ alert(& ...

  3. springboot整合druid数据库连接池并开启监控

    简介 Druid是一个关系型数据库连接池,它是阿里巴巴的一个开源项目.Druid支持所有JDBC兼容的数据库,包括Oracle.MySQL.Derby.PostgreSQL.SQL Server.H2 ...

  4. 【BZOJ】2734: [HNOI2012]集合选数

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2734 考虑$N=4$的情况: \begin{bmatrix} 1&3 &X ...

  5. Educational Codeforces Round 3 D. Gadgets for dollars and pounds 二分+前缀

    D. Gadgets for dollars and pounds time limit per test 2 seconds memory limit per test 256 megabytes ...

  6. Hash——字符串匹配(求s1在s2中出现的次数)

    题目描述: 这是一道模板题. 给定一个字符串 A 和一个字符串 B ,求 B 在 A  中的出现次数.A 和 B中的字符均为英语大写字母. 求A 在 B 中出现了几次.(可重叠) 样例输入: 3 BA ...

  7. ZZNU 正约数之和

    #include<stdio.h> #include<string.h> #include<math.h> #include<time.h> #incl ...

  8. fileInputStream.available()获取 文件的总大小

    available():返回与之关联的文件的字节数 我们用inputStream.available()获取 文件的总大小

  9. 《剑指offer》第四十六题(把数字翻译成字符串)

    // 面试题46:把数字翻译成字符串 // 题目:给定一个数字,我们按照如下规则把它翻译为字符串:0翻译成"a",1翻 // 译成"b",……,11翻译成&qu ...

  10. word空白页怎么删除

    最简单的,直接按键盘上的BackSpace或者Delete键,来进行删除.  分页符过到.打开“编辑”-->替换-->高级-->特殊字符-->手工分页符-->“全部替换” ...