17. Letter Combinations of a Phone Number
来源:互联网 发布:淘宝商品如何推广 编辑:程序博客网 时间:2024/06/15 20:24
public static List<String> letterCombinations(String digits) { List<String> list1 = new ArrayList<String>(); List<String> list2 = new ArrayList<String>(); List<String> list = list1; List<String> listtmp = list2; List<String> listcc = null; if(digits == null || digits.length() == 0) { return list; } String[] a = new String[]{ "","","abc","def", "ghi","jkl","mno", "pqrs","tuv","wxyz" }; int len = digits.length(); for(int i = 0; i < len ; i++) { String str = a[char2num(digits.charAt(i))]; int strLen = str.length(); if(strLen != 0) { if(!list.isEmpty()) { listtmp.clear(); for(int j = 0; j < list.size(); j++) { String strTmp = list.get(j); for(int k = 0; k < strLen; k++) { listtmp.add(strTmp + str.charAt(k)); } } list.clear(); listcc = listtmp; listtmp = list; list = listcc; }else { for(int j =0 ; j < strLen; j++){ list.add(String.valueOf(a[char2num(digits.charAt(i))].charAt(j))); } } } } return list; } public static int char2num(char c) { int i = 0; switch(c) { case '0' :i =0 ;break; case '1' :i =1 ;break; case '2' :i =2 ;break; case '3' :i =3 ;break; case '4' :i =4 ;break; case '5' :i =5 ;break; case '6' :i =6 ;break; case '7' :i =7 ;break; case '8' :i =8 ;break; case '9' :i =9 ;break; } return i; }
0 0
- 17.Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- ChecBox全选
- Android UI 优化工具HierarchyViewer---阿冬专栏
- ResultMapping 错误之标记类名后转发路径错误问题
- awk
- 无意中发现其它网站使用我的文章
- 17. Letter Combinations of a Phone Number
- 【数据结构】单链表上的基本运算
- 文件
- Sum Problem
- 浅析互斥锁与条件变量的使用
- 打开转发IP功能(IP forwarding)
- java load property
- 传纸条 优化
- linux文件学习9