简单的回溯法!

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. Docker:Deploy your app

    Prerequisites Install Docker. Get Docker Compose as described in Part 3 prerequisites. Get Docker Ma ...

  2. 几个C++ online test 网站

    http://www.mycppquiz.com/list.php http://www.codelect.net/TestDetails/Cplusplus-Senior-Level-Test ht ...

  3. 转载:避免重复插入,更新的sql

    本文章来给大家提供三种在mysql中避免重复插入记录方法,主要是讲到了ignore,Replace,ON DUPLICATE KEY UPDATE三种方法,各位同学可尝试参考. 案一:使用ignore ...

  4. SAP按销售订单生产和标准结算配置及操作手册

    SAP按销售订单生产和标准结算配置及操作手册 http://blog.sina.com.cn/s/blog_6787c0b80101a3tl.html SAP按销售订单生产和标准结算配置及操作手册 S ...

  5. CSS属性大全

    字体属性:(font)大小 font-size:x-large;(特大) xx-small;(极小) 一般中文用不到,只要用数值就可以,单位:PX.PD样式 font-style:oblique;(偏 ...

  6. PHP 内置函数fgets读取文件

    php fgets()函数从文件指针中读取一行 语法: fgets(file,length) 参数 描述 file  必需.规定尧要读取的文件 length 可选 .规定尧都区的字节数.默认是102字 ...

  7. WebBrowser获取完整COOKIE

    [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern bool ...

  8. IOS学习笔记一1

    //创建.h文件 界面的类文件(创建一个类) @interface MyClass:NSObject{ //类变量声明 int a; int b; } //类属性声明 (int) p2 //类方法声明 ...

  9. java根据地址获取百度API经纬度

    java根据地址获取百度API经纬度(详细文档) public void getLarLng(String address) throws Exception { String ak = " ...

  10. Java 中常见的各种排序算法汇总

    首先,Java中自已是有排序的 说明:(1)Arrays类中的sort()使用的是“经过调优的快速排序法”;(2)比如int[],double[],char[]等基数据类型的数组,Arrays类之只是 ...