package stevesun.algorithms;
import java.util.*;
/**
 * Created by fishercoder1534 on 10/3/16.
 */
public class LetterCombinationsofaPhoneNumber {

    public List<String> letterCombinations(String digits) {
        String[] digits2Letters = new String[]{"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

        List<String> result = new ArrayList();
        if(digits.length() == 0) return result;

        result.add("");//this line is important, otherwise result is empty and Java will default it to an empty String
        for(int i = 0; i < digits.length(); i++){
            result = combine(digits2Letters[digits.charAt(i)-'0'], result);
        }

        return result;
    }

    List<String> combine(String letters, List<String> result){
        List<String> newResult = new ArrayList();

        for(int i = 0; i < letters.length(); i++){//the order of the two for loops doesn't matter, you could swap them and it still works.
            for(String str : result){
                newResult.add(str + letters.charAt(i));
            }
        }

        return newResult;
    }

}

@@ -22,16 +22,17 @@
 rithms;%0A
+%0A
 import j
@@ -47,58 +47,399 @@
 .*;%0A
+%0A
 /**%0A * 
-Created by fishercoder1534 on 10/3/16
+Given a digit string, return all possible letter combinations that the number could represent.%0A%0A A mapping of digit to letters (just like on the telephone buttons) is given below.%0A%0A Input:Digit string %2223%22%0A Output: %5B%22ad%22, %22ae%22, %22af%22, %22bd%22, %22be%22, %22bf%22, %22cd%22, %22ce%22, %22cf%22%5D.%0A Note:%0A Although the above answer is in lexicographical order, your answer could be in any order you want
 .%0A */%0A
+%0A
 publ
@@ -1403,33 +1403,32 @@
     %7D%0A        %7D%0A
-%0A
         return n
@@ -1443,11 +1443,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

add problem description