017.Letter Combinations of a Phone Number Posted on 2017-09-13 | In LeetCode Solution 1: accepted 4msPretty massy, need to be improved. 12345678910111213141516171819202122232425262728293031public List<String> letterCombinations(String digits) { List<String> result = new ArrayList<>(); String[] map = {"", "", "abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; for (int i = 0; i < digits.length(); i++) { char digit = digits.charAt(i); if (digit == '0' || digit == '1') return new ArrayList<>(); result = appendAll(result, map[digit - '0']); } return result;}public List<String> appendAll(List<String> result, String chars) { List<String> update = new ArrayList<>(); Iterator<String> it = result.iterator(); if (result.size() == 0) { for (int i = 0; i < chars.length(); i++) { update.add(chars.charAt(i) + ""); } } else { while(it.hasNext()) { String current = it.next(); for (int i = 0; i < chars.length(); i++) { update.add(current + chars.charAt(i)); } } } return update;}