[LC] 17. Letter Combinations of a Phone Number
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
Time: O(3^N)
class Solution {
private String[] letters = {"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
public List<String> letterCombinations(String digits) {
List<String> res = new ArrayList<>();
if (digits == null || digits.length() == 0) {
return res;
}
helper(res, "", digits, 0);
return res;
}
private void helper(List<String> res, String s, String digits, int index) {
if (s.length() == digits.length()) {
res.add(s);
return;
}
String curLetter = letters[digits.charAt(index) - '0'];
// loop through current letters[index]
for (int i = 0; i < curLetter.length(); i++) {
helper(res, s + curLetter.charAt(i), digits, index + 1);
}
}
}
[LC] 17. Letter Combinations of a Phone Number的更多相关文章
- [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所有可能的输出: ...
- 《LeetBook》leetcode题解(17):Letter Combinations of a Phone Number[M]
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合
Given a string containing digits from 2-9inclusive, return all possible letter combinations that the ...
- 17. Letter Combinations of a Phone Number
题目: Given a digit string, return all possible letter combinations that the number could represent. A ...
- [leetcode 17]Letter Combinations of a Phone Number
1 题目: Given a digit string, return all possible letter combinations that the number could represent. ...
- Java [leetcode 17]Letter Combinations of a Phone Number
题目描述: Given a digit string, return all possible letter combinations that the number could represent. ...
- Leetcode 17.——Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
随机推荐
- 基于基因调控网络(Hopfield network)构建沃丁顿表观遗传景观
基因调控网络的概念在之前已经简要介绍过:https://www.cnblogs.com/pear-linzhu/p/12313951.html 沃丁顿表观遗传景观(The Waddington's e ...
- 下面介绍mysql中模糊查询的四种用法:
下面介绍mysql中模糊查询的四种用法: 1,%:表示任意0个或多个字符.可匹配任意类型和长度的字符,有些情况下若是中文,请使用两个百分号(%%)表示. 比如 SELECT * FROM [user] ...
- 干货|Kubernetes集群部署
Nginx-ingress Controller
Kubernetes提供了两种内建的云端负载均衡机制用于发布公共应用,一种是工作于传输层的Service资源,它实现的是TCP负载均衡器:另一种是Ingress资源,它实现的是HTTP(S)负载均衡器 ...
- python语法基础-并发编程-进程-进程锁和进程间通信
############### 守护进程 ############## """ 守护进程 父进程中将一个子进程设置为守护进程,那么这个子进程会随着主进程的结束而结束 ...
- 关于maven的使用总结
maven介绍 项目构建过程 eclipse只是开发工具,虽然提供了创建.编码.编译.测试.运行等功能,但并不是项目构建工具. 项目构建主要过程如下: 实际的项目构建过程要复杂繁琐的多.如果是一个独立 ...
- JavaSE--数字签名之校验签名
参考:http://blog.csdn.net/dotuian/article/details/51722300 关于keystore的简单介绍 Keytool是一个Java数据证书的管理工具 ,Ke ...
- 9.windows-oracle实战第九课--plsql
一.oracle的pl/sql的概念 pl/sql是oracle在标准的sql语言上的扩展,不仅允许嵌入sql,还允许定义变量和常量,允许使用条件语句和循环语句,允许使用例外处理各种错误,这样使得它的 ...
- C语言代码在内存中的存储
http://blog.chinaunix.net/uid-26430381-id-4359960.html
- [HNOI2019]校园旅行(建图优化+bfs)
30分的O(m^2)做法应该比较容易想到:令f[i][j]表示i->j是否有解,然后把每个路径点数不超过2的有解状态(u,v)加入队列,然后弹出队列时,两点分别向两边搜索边,发现颜色一样时,再修 ...
- php先响应后处理
php响应异步请求或者返回时效要求高的接口中,可以先响应输出,再执行逻辑处理保存数据等任务 ob_end_clean(); ob_start(); echo '{"data":&q ...