17. Letter Combinations of a Phone Number

#### QUESTION:

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"].
``````

Note: Although the above answer is in lexicographical order, your answer could be in any order you want.

#### SOLUTION:

``````class Solution {
static String[][] im = new String[10][3];
static{
im[2] = new String[]{"a","b","c"};
im[3] = new String[]{"d","e","f"};
im[4] = new String[]{"g","h","i"};
im[5] = new String[]{"j","k","l"};
im[6] = new String[]{"m","n","o"};
im[7] = new String[]{"p","q","r","s"};
im[8] = new String[]{"t","u","v"};
im[9] = new String[]{"w","x","y","z"};
}
public List<String> letterCombinations(String digits) {
if(digits.isEmpty()) return new ArrayList<>();
if(digits.contains("1")) return new ArrayList<>();
if(digits.contains("*")||digits.contains("#")) return null;
ArrayList<String> result = new ArrayList<>();
letterCombinationsHelper("",digits.toCharArray(),result,0);
return result;
}
public void letterCombinationsHelper(String subString,char[] chars,List<String> result,int start){
if (subString.length() == chars.length) {