就dfs吧....

然后,我傻了。前一道题不用考虑空,这道题就要考虑。。。。

还有注意vector要引用传递

class Solution {

public:
void dfs(string temp,vector<string>&ret,string digits,int index,string* str,int len)
{
if(index==len)
{
ret.push_back(temp);
return;
}
else
{
int n=str[(digits[index]-'2')].length();
for(int i=0;i<n;i++)
dfs((temp+str[(digits[index]-'2')][i]),ret,digits,index+1,str,len);
}
} public:
vector<string> letterCombinations(string digits) {
vector<string>ret;
if(digits=="")
return ret;
string str[10] = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
int len=digits.length();
string temp="";
this->dfs(temp,ret,digits,0,str,len);
return ret;
}
};

另外有点震惊:这是机器性能太强还是测试用例太少奥

leetcode17 电话号码的字母组合 dfs的更多相关文章

  1. Leetcode13. 罗马数字转整数Leetcode14. 最长公共前缀Leetcode15. 三数之和Leetcode16. 最接近的三数之和Leetcode17. 电话号码的字母组合

    > 简洁易懂讲清原理,讲不清你来打我~ 输入字符串,输出对应整数 ![在这里插入图片描述](https://img-blog.csdnimg.cn/63802fda72be45eba98d9e4 ...

  2. [Swift]LeetCode17. 电话号码的字母组合 | Letter Combinations of a Phone Number

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

  3. Java实现LeetCode17. 电话号码的字母组合

    给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:"23" 输出:[&quo ...

  4. LeetCode17.电话号码的字母组合 JavaScript

    给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:"23" 输出:[&quo ...

  5. Leetcode之回溯法专题-17. 电话号码的字母组合(Letter Combinations of a Phone Number)

    [Leetcode]17. 电话号码的字母组合(Letter Combinations of a Phone Number) 题目描述: 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组 ...

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

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

  7. lintcode 中等题:Letter Combinations of a Phone Number 电话号码的字母组合

    题目 电话号码的字母组合 给一个数字字符串,每个数字代表一个字母,请返回其所有可能的字母组合. 下图的手机按键图,就表示了每个数字可以代表的字母. 样例 给定 "23" 返回 [& ...

  8. LeetCode(17):电话号码的字母组合

    Medium! 题目描述: 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:"23& ...

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

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

随机推荐

  1. jQuery库 之 jquery slimscroll插件使用

    1.引入jQuery插件 <script type="text/javascript" src="jquery.min.js"></scrip ...

  2. vue+element-ui:table表格中的slot 、formatter属性

    slot 插槽,table中表示该行内容以自定义方式展示 :formatter 方法,用来格式化内容 Function(row, column, cellValue, index) html < ...

  3. 07. struts2中对Action的管理方式

    web.xml配置文件的常用代码 <filter> <filter-name>struts2</filter-name> <filter-class>o ...

  4. day03 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4.递归 5.匿名函数 6.函数式编程介绍 7.高阶函数 8.内置函数

    本节内容 1. 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4.递归 5.匿名函数 6.函数式编程介绍 7.高阶函数 8.内置函数 温故知新 1. 集合 主要作用: 去重 关系测 ...

  5. Android字节码优化工具redex初探

    https://mp.weixin.qq.com/s/Og2TkGrZR490h9-KO23lmw 背景 apk瘦身和启动时间优化是移动端开发性能优化中经常被提到的两个问题.apk瘦身的常规做法有,s ...

  6. (004)每日SQL学习:物化视图之二

    一.    物化视图概述 Oracle的物化视图是包括一个查询结果的数据库对像,它是远程数据的的本地副本,或者用来生成基于数据表求和的汇总表.物化视图存储基于远程表的数据,也可以称为快照. 物化视图可 ...

  7. 就是通过事件方法,在window.loaction.href里追加了参数字符串

    参考博文:https://www.kancloud.cn/digest/yvettelau/137669

  8. Jenkins部署springboot项目

    记录jenkins如何部署springboot项目(jar类型的) 一.首先需要先配置好jenkins的基本配置(jdk.maven--),可在系统管理-->>全局工具配置中进行配置. 配 ...

  9. OPC UA 统一架构) (二)

    OPC UA (二) 重头戏,捞取数据,才是该干的事.想获取数据,先有数据源DataPrivade,DataPrivade的数据集合不能和BaseDataVariableState的集合存储同一地址, ...

  10. 「笔记」数位DP

    目录 写在前面 引入 求解 特判优化 代码 例题 「ZJOI2010」数字计数 「AHOI2009」同类分布 套路题们 「SDOI2014」数数 写在最后 写在前面 19 年前听 zlq 讲课的时候学 ...