标签:ons generated lis port method arraylist shm pre import
package leetcode17; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; public class PhoneNumberDemo01 { } class Solution { public List<String> letterCombinations(String digits) { Map<Integer, List<Character>> map = new HashMap<Integer, List<Character>>(); map.put(2, Arrays.asList(‘a‘, ‘b‘, ‘c‘)); map.put(3, Arrays.asList(‘d‘, ‘e‘, ‘f‘)); map.put(4, Arrays.asList(‘g‘, ‘h‘, ‘i‘)); map.put(5, Arrays.asList(‘j‘, ‘k‘, ‘l‘)); map.put(6, Arrays.asList(‘m‘, ‘n‘, ‘o‘)); map.put(7, Arrays.asList(‘p‘, ‘q‘, ‘r‘, ‘s‘)); map.put(8, Arrays.asList(‘t‘, ‘u‘, ‘v‘)); map.put(9, Arrays.asList(‘w‘, ‘x‘, ‘y‘, ‘z‘)); int len = digits.length(); List<String> list = new ArrayList<String>(); List<Character> path = new ArrayList<Character>(); if(len==0) { return list; } dfs("",list,len,0,map,path); } private void dfs(String res,List<String> list, int len,int depth, Map<Integer, List<Character>> map,List<Character> path ) { // TODO Auto-generated method stub if(len == depth) { // list.add(pa); list.add(res); } List<Character> list2 = map.get(depth); for(int i=0;i<list2.size();i++) { dfs(res+, list, len, depth, map, path); } } }
标签:ons generated lis port method arraylist shm pre import
原文地址:https://www.cnblogs.com/lt123/p/13787124.html