LeetCode题解:Letter Combinations of a Phone Number
来源:互联网 发布:windows bitlocker 编辑:程序博客网 时间:2024/05/16 19:04
Given a digit string, 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.
Input:Digit string “23”
Output: [“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “cf”].
题意:求给定字符串,按照给定映射关系能得到的所有字符组合
解题思路:用数组装每一个按键对应的可选字符,然后根据输入一一组合
代码:
public class Solution { private static final String[] KEYS = { "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" }; public List<String> letterCombinations(String digits) { List<String> ret = new LinkedList<String>(); if(digits.length() == 0){ return ret; } combination("", digits, 0, ret); return ret; } private void combination(String prefix, String digits, int offset, List<String> ret) { if (offset >= digits.length()) { ret.add(prefix); return; } String letters = KEYS[(digits.charAt(offset) - '0')]; for (int i = 0; i < letters.length(); i++) { combination(prefix + letters.charAt(i), digits, offset + 1, ret); } }}
0 0
- LeetCode题解:Letter Combinations of a Phone Number
- leetcode 题解 || Letter Combinations of a Phone Number 问题
- LeetCode 题解(77): Letter Combinations of a Phone Number
- LeetCode题解——Letter Combinations of a Phone Number
- LeetCode题解:Letter Combinations of a Phone Number
- 【leetcode题解】【M】【67】Letter Combinations of a Phone Number
- LEETCODE 17 Letter Combinations of a Phone Number (JAVA题解)
- 17. Letter Combinations of a Phone Number LeetCode题解
- Leetcode题解-17. Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- LeetCode Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- [Leetcode] Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- 【leetcode】Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- [LeetCode]Letter Combinations of a Phone Number
- LeetCode-Letter Combinations of a Phone Number
- Linux源代码分析工具链
- 用报表系工具搭建证书查询系统示例
- jenkins中配置powershell生成svn日志(word)
- DWR框架快速入门<学习随笔>
- Android 学习历程摘要(五)
- LeetCode题解:Letter Combinations of a Phone Number
- libgdx骨骼动画例子
- oracle学习笔记 ---- 多表联查
- ZOJ 1047 Image Perimeters
- 北大是泉水,清华是岩浆
- LeetCode(233)Number of Digit One
- 使用Samba实现Linux与Windows文件共享实践
- 模板文件读取和输出
- 八月,整理一些无聊的资料,以便无聊的时候看