简单的回溯法!

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. matplotlib python

    #导入包 import matplotlib.pyplot as plt import numpy as np # 从[-1,1]中等距去50个数作为x的取值 x = np.linspace(-1, ...

  2. vue.js精讲02

    2017-09-17 笔记及源码地址 : https://github.com/wll8/vue_note vue 中的事件深入. 事件: @click/mouseover…事件简写: @ 如 @cl ...

  3. 增强 用文本增强修改SAP标准屏幕中的字段名称 属于元素的文本增强

    如果想要改变标准屏幕中的字段名称,如把物料主数据基本数据元素的名字改为我们想要的名字 . 1.首先,事务MM03进入物料主数据的基本数据2视图中,将鼠标光标放在需要更改的字段“页格式”上,然后按F1键 ...

  4. Jenkins参数化构建(二)之 Maven command line使用Jenkins参数

    安装Extened Choice Parameter插件 General模块选择‘参数化构建过程’   3. maven command line中使用 clean test -DsuiteXmlFi ...

  5. MInio python

    # Install Minio library. # $ pip install minio # # Import Minio library. from minio import Minio # I ...

  6. springmvc通过ajax异步请求返回json格式数据

    jsp 首先创建index.jsp页面 <script type="text/javascript"> $(function () { $("#usernam ...

  7. 【Python】【有趣的模块】【requests】【二】快速上手

    [一]参数及结果 [二]响应内容 >>> r = requests.get('https://github.com/timeline.json') >>> prin ...

  8. Oracel 中的分页

    --效率低 select * from (select rownum rn, d.* from table d )p where p.rn<=20 and p.rn>=10; select ...

  9. openmodelica警告及错误

    Warning: The initial conditions are not fully specified. simulate(TCS.TCS,startTime=0,stopTime=200.0 ...

  10. Hadoop大数据分析应用场景

    J 为了满足日益增长的业务变化,京东的京麦团队在京东大数据平台的基础上,采用了hadoop等热门的开源大数据计算引擎,打造了一款为京东运营和产品提供决策性的数据类产品-北斗平台. 一.Hadoop的应 ...