Letter Combinations of a Phone Number
来源:互联网 发布:河北师范大学网络 编辑:程序博客网 时间:2024/06/16 12:44
Problem: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 static List<String> letterCombinations(String digits) {List<String> result = new ArrayList<String>();if(digits.isEmpty())return result;String[] map ={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};int[] number = new int[digits.length()];//存储digits中每个字符在循环中的编号,初始为0int k = digits.length()-1;while(k>=0) {k = digits.length()-1;String charTemp="";for(int i=0; i<digits.length(); i++) charTemp+=String.valueOf(map[digits.charAt(i)-'0'].charAt(number[i]));result.add(charTemp);while(k>=0) {if( number[k] < (map[digits.charAt(k)-'0'].length()-1) ) {number[k]++;break;} else {number[k] = 0;k--;}}}return result;}
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
- Jquery获取值
- mysql 数据和索引的存储关系
- 第一周刷题总结
- 关于Objective-c 中私有方法的几点总结
- 工厂方法模式
- Letter Combinations of a Phone Number
- codeforces #312 558D D. Guess Your Way Out! II(排序离散化)
- 暑假集训
- WordPress常用代码调用大全
- [cocos2dx]可视元素——CCLayer图层类
- IOS多线程之dispatch_once剖析
- Linux常用命令之mkdir/cp
- Excel数据导入___你hold住么(一)
- eclipse常用快捷键