GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/code/lc17.java at master · mJackie/leetcode Expand file tree/ Copy pathlc17.javaMore file actions 35 lines (33 loc) · 1.11 KB / Copy pathlc17.javaFile metadata and controls35 lines (33 loc) · 1.11 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 package code; import java.util.List; import java.util.Vector; /* * 17. Letter Combinations of a Phone Number * 题意:手机键盘字母输入 * 难度:Medium * 思路:思路记一下,每次放到vector中,遍历vector,加上所有的可能 * 分类:String, Backtracking */ public class lc17 { public static void main(String[] args) { System.out.println(letterCombinations("23").toString()); } public static List<String> letterCombinations(String digits) { Vector<String> res = new Vector<>(); if(digits.length()==0) return res; String[] charmap = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; res.add(""); for (int i = 0; i < digits.length(); i++) { int n = digits.charAt(i)-'0'; Vector<String> temp_res = new Vector<>(); for (int j = 0; j < charmap[n].length(); j++) { for (int k = 0; k < res.size(); k++) { temp_res.add(res.get(k)+charmap[n].charAt(j)); } } res = temp_res; } return res; } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |