leetcode个人题解——#17 Letter Combinations of a Phone Number
思路:用深搜遍历九宫格字符串,一开始做的时候发生了引用指向空地址的问题,后来发现是vector不能直接=赋值。
class Solution {
public:
int len;
string map[]={"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
void search(int pos, string res, vector<string>& a, string digits){
if(pos == len) return;
string s = map[digits[pos] - ''];
for (int i = ;i < s.size(); i++)
{
if(pos == len - )a.push_back(res + s[i]);
else search(pos + , res + s[i], a, digits);
}
}
vector<string> letterCombinations(string digits) {
vector<string> ans;
len = digits.size();
if(len == )return ans;
search(,"",ans,digits);
return ans;
}
};
leetcode个人题解——#17 Letter Combinations of a Phone Number的更多相关文章
- 《LeetBook》leetcode题解(17):Letter Combinations of a Phone Number[M]
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- [LeetCode][Python]17: Letter Combinations of a Phone Number
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 17: Letter Combinations of a Phone Numb ...
- 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 ...
- 刷题17. Letter Combinations of a Phone Number
一.题目说明 题目17. Letter Combinations of a Phone Number,题目给了下面一个图,输入一个字符串包括2-9,输出所有可能的字符组合. 如输入23所有可能的输出: ...
- [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合
Given a string containing digits from 2-9inclusive, return all possible letter combinations that the ...
- 【LeetCode】17. Letter Combinations of a Phone Number 电话号码的字母组合
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:电话号码, 字母组合,回溯法,题解,leetcode, ...
- [leetcode 17]Letter Combinations of a Phone Number
1 题目: Given a digit string, return all possible letter combinations that the number could represent. ...
- 【一天一道LeetCode】#17. Letter Combinations of a Phone Number
一天一道LeetCode (一)题目 Given a digit string, return all possible letter combinations that the number cou ...
- Java [leetcode 17]Letter Combinations of a Phone Number
题目描述: Given a digit string, return all possible letter combinations that the number could represent. ...
随机推荐
- Cornerstone|SVN
SQLite-database disk image is malformed missing from working copy mac下CornerstoneSVN出错 Description _ ...
- Zabbix——设置报警阈值
前提条件: 1. Zabbix-server 版本为4.0 2.邮件告警正常使用 3. 阈值改为1分钟进行邮件发送 点击: 找到agent,点击触发器: 设置网络ping包进行检测
- 分布式网上商城项目- BeanDefinitionStoreException
BeanDefinitionStoreException: 严重: StandardWrapper.Throwable org.springframework.beans.factory.BeanDe ...
- laravel-admin 创建数据库并生成控制器
以user表为例 1. 生成迁移:php artisan make:migration create_users_table 在 database/migration 中生成迁移文件,可对迁移文件进行 ...
- Hive的内置函数
定义: UDF(User-Defined-Function),用户自定义函数对数据进行处理. UDTF(User-Defined Table-Generating Functions) 用来解决 输入 ...
- Python学习:7.文件操作
文件操作 我们曾将听过一个问题,将大象放入冰箱分为三步:1.打开冰箱门,2.将大象放进去,3.关上冰箱门.今天我们要讲的Python文件操作的步骤就像将大象放入冰箱的步骤一样. 使用Python操作文 ...
- aes并发加密Cipher not initialized 异常
javax.crypto.Cipher 每次都要实例化,大量的实例化导致 Cipher 实例化失败. 解决办法:将已经实例化的Cipher对象,放在hashmap中,每次实例化的时候从MAP 获取,不 ...
- xshell5连接虚拟机的小问题处理
1.首先确保虚拟机是桥接状态,然后在虚拟机下用ifconfig查看ip地址(当然是默认你虚拟机下是linux) 2.确保虚拟机安装了ssh...安装openssh-server: 对应的sudo ap ...
- [原创]python高可用程序设计方法
有时候程序上的bug会导致程序引发诸如段错误的情况而导致程序异常退出,这时用crond服务来检测,就会有一段时间程序处于不可用的情况,为了增强程序的可用性,我们可以让子进程处理业务,而让主进程检测子进 ...
- vue跨域访问
第一次创建vue项目,画完静态页面一切顺利,准备和后台进行联调,问题来了,无论怎么调试使用Axios,jQuary还是使用原生的Ajax请求都访问不通(前提条件,另外一个人的电脑当成服务器,进行访问) ...