[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 ...
 
随机推荐
- 洛谷P4071-[SDOI2016]排列计数 题解
			
SDOI2016-排列计数 发现很多题解都没有讲清楚这道题为什么要用逆元.递推公式怎么来的. 我,风雨兼程三十载,只为写出一篇好题解. 还是我来造福大家一下吧. 题目大意: 一个长度为 n 且 1~n ...
 - python3转义编码
			
s = 'dy电影' print(s) # dy电影 print(type(s)) # <class 'str'> print(s.encode('utf-8')) # b'dy\xe7\ ...
 - 吴裕雄--天生自然深度学习TensorBoard可视化:projector_MNIST
			
import os import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data from te ...
 - 第1章 分布式系统概念与ZooKeeper简介
			
ZooKeeper分布式专题与Dubbo微服务入门 第1章 分布式系统概念与ZooKeeper简介 1-1 zookeeper简介 1-2 什么是分布式系统 略 1-3 分布式系统的瓶颈以及zk的相关 ...
 - 微信小程序使用第三方FontIcon库的部分字体图标
			
一.提取部分图标重新制作TTF字库 我没有使用网上大多数文章写的淘宝提供的fonticon,而只使用了Ionicons的几个图标,所以打开Ionicons的官网点击右上角的Designer pack下 ...
 - Linux进程的诞生和消亡
			
1.进程的诞生 (1).进程0和进程1 (内核里边的固有的) (2).fork函数和vfork函数用于新进程的产生 2.进程的消亡 (1).正常终止和异常终止 (2).进程在运行时需要消耗系统资源(内 ...
 - Eclipse打包Jar单独使用
			
今天做了一个刷***的功能,代码很简单,只有几十行代码,我开始是在eclipse里面跑的,后面觉得在里面跑不舒服,我就想把他单独作为一个jar文件单独运行,里面使用了第三方jar包,下面记录一下步骤. ...
 - JavaScript学习笔记 - 入门篇(1)- 准备
			
为什么学习JavaScript 一.你知道,为什么JavaScript非常值得我们学习吗? 所有主流浏览器都支持JavaScript. 目前,全世界大部分网页都使用JavaScript. 它可以让网页 ...
 - 分享一套好看的PyCharm Color Shceme 配色方案
			
配色方案图1 点击可查看大图 (color shceme 配色文件下载链接已经放在文末) 配色方案图2 配色方案图3 picture1 picture2 整体效果 下载链接 https://files ...
 - Python笔记_第一篇_面向过程_第一部分_6.其他控制语句(with...as等)
			
其他控制语句,也就是说一个with... as...语句. 这是python非常精妙的一个语句,非常的简单但是作用非常大,在打开文件获得句柄的时候可以用它,省去f.close()忘记添加的麻烦(这个文 ...