Letter Combination of phone number
来源:互联网 发布:淘宝定做衣服 编辑:程序博客网 时间:2024/05/17 02:12
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 LetterCombinationsOfAPhoneNumber{public List<String> letterCombinations(String digits){LinkedList<String> ans = new LinkedList<String>();String[] mapping = {"0","1","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};if(digits == null || digits.length() == 0){return ans;}ans.add("");for(int i=0; i<digits.length();i++){int x = Character.getNumericValue(digits.charAt(i));while(ans.peek().length() == i){//取出第一个字符串,将其长度与当前数字的位数进行比较String t = ans.removeFirst();//Or ans.remove();for(char s : mapping[x].toCharArray()){ans.add(t+s);}}}return ans;}}
阅读全文
0 0
- Letter Combination of phone number
- Letter Combination of phone number
- Letter Combination of a Phone Number
- leetcode-letter combination of a phone number
- [Leetcode] 17. Letter Combination of a Phone Number
- leetcode-17 Letter Combination of a Phone Number
- Python 刷题日记: Letter Combination of a Phone Number
- FTPrep, 17 letter combination of a phone number
- Letter combinations of 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
- LeetCode18:Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- 【leetcode】Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- c++实验5-数组分离
- Android源码中编译AndroidStudio工程
- MySQL查询某段时间某经度范围内的数据
- 博隆过滤器
- Linux命令基础33-date命令
- Letter Combination of phone number
- 设计模式之装饰者模式
- 代理服务器和网络地址转换NAT
- 使用 Comparable 接口实现对象的属性排序
- forward(转发)和redirect(重定向)的区别
- hrbust 2256 南西群岛海域·冲之岛近海(暴力)
- 动态调用action
- Python 字典
- bzoj 2819: Nim 树状数组+dfs序