Letter Combinations of a Phone Number
来源:互联网 发布:生化危机6 知乎 编辑:程序博客网 时间:2024/05/16 05:20
Given a digit string, return all possible letter combinations that the number could represent.
Input:Digit string "23"Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
public List<String> letterCombinations(String digits) {LinkedList<String> ans = new LinkedList<String>();String[] mapping = new String[] { "0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };if (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.remove();for (char s : mapping[x].toCharArray())ans.add(t + s);}}return ans;}
0 0
- 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
- 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
- Letter Combinations of a Phone Number
- [LeetCode] 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
- COCI CONTEST #3 29.11.2014 T4 HONI
- 排序III
- coreData
- openstack部署(3)-安装glance组件
- Web开发设计(一)
- Letter Combinations of a Phone Number
- 黑马程序员_tomcat 配置数据源和连接池
- COCI CONTEST #3 29.11.2014 T5 STOGOVI
- hdu 1285 邻接表数组实现
- POJ - 1905-Expanding Rods-数论-二分&几何
- 延展、协议
- 【POJ 3264】 Balanced Lineup (RMQ)
- android学习笔记(二)—— 常用布局与控件
- hdu 1829 A Bug's Life (判断二分图)