就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. undefined和null区别

    undefined类型只有一个值就是undefined,没有必要显式地声明一个变量为undefined. null类型其实就是一个对象的空指针,所以用typeof null 才会显示为object. ...

  2. 通过SE14重建数据库表

    通过程序中的SQL语句向数据库表中插入的内容,系统无法转换,并且已经存在于数据库表中,那么当对该表进行保存数据的修改时,可能会导致该表从数据库中的删除. 举了例子:(完全是为了方便理解) SAP系统, ...

  3. REUSE_ALV_FIELDCATALOG_MERGE函数

    今天使用REUSE_ALV_FIELDCATALOG_MERGE函数,就是获取不到fieldcat, 搞了半天才发现,原来参数要全部大写才行!!小写字符就是获取不到,唉,悲哀...

  4. Dubbo的设计理念原来就藏在这三张图中

    Dubbo在众多的微服务框架中脱颖而出,占据RPC服务框架的半壁江山,非常具有普适性,熟练掌握 Dubbo的应用技巧后深刻理解其内部实现原理,让大家能更好的掌控工作,助力职场,特别能让大家在面试中脱颖 ...

  5. 指针锁定 Pointer Lock API 用法

    指针锁定 Pointer Lock API 通过它可以访问原始的鼠标运动(基于指针的相对位移 movementX / movementY),把鼠标事件的目标锁定到一个特定的元素,同时隐藏视图中的指针光 ...

  6. 翻译 - ASP.NET Core 基本知识 - Web 主机 (Web Host)

    翻译自 https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/web-host?view=aspnetcore-5.0 ASP. ...

  7. 使用EFCore连接Oracle数据库时出现的问题

    问题 System.TypeLoadException: Method 'Create' in type 'Oracle.EntityFrameworkCore.Infrastructure.Inte ...

  8. https://www.cs.cmu.edu/~dga/papers/cuckoo-conext2014.pdf 检验hash冲突

    https://github.com/google/cityhash We like to test hash functions with SMHasher, among other things. ...

  9. 《Effective C#》之减少装箱和拆箱

    <Effective C#>之减少装箱和拆箱_天极网 http://dev.yesky.com/msdn/359/3486359.shtml <Effective C#>之减少 ...

  10. LOJ10160周年纪念晚会

    题目描述 Ural 州立大学的校长正在筹备学校的 80 周年纪念聚会.由于学校的职员有不同的职务级别,可以构成一棵以校长为根的人事关系树.每个资源都有一个唯一的整数编号,从 1 到 N 编号,且对应一 ...