@@ -0,0 +1,2061 @@
+package algorithms.a11_to_a20.a17_LetterCombinationsOfAPhoneNumber_Medium;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * Created by 31798 on 2016/8/22.%0A */%0A// #Backtracking#, #String#%0Apublic class Solution %7B%0A%0A    public List%3CString%3E ans = new ArrayList%3C%3E();%0A%0A    public List%3CString%3E letterCombinations(String digits) %7B%0A        if (digits == %22%22) %7B%0A            return null;%0A        %7D%0A        dfs(digits, 0, %22%22);%0A        return ans;%0A    %7D%0A%0A    public void dfs(String digits, int pos, String tmp) %7B%0A        if (pos == digits.length() ) %7B%0A            if (tmp != %22%22) %7B%0A                ans.add(tmp);%0A            %7D%0A            return;%0A        %7D%0A        List%3CCharacter%3E all = allLetters(digits.charAt(pos));%0A        if (all.size() == 0) %7B%0A            dfs(digits, pos + 1, tmp);%0A        %7D else for (Character c : all) %7B%0A            dfs(digits, pos + 1, tmp + c);%0A        %7D%0A    %7D%0A%0A    public List%3CCharacter%3E allLetters(char digit) %7B%0A        List%3CCharacter%3E characters = new ArrayList%3C%3E();%0A        if (digit %3E= '2' && digit %3C= '7') %7B%0A            for (int i = 0; i %3C 3; i++) %7B%0A                characters.add((char) ((digit - '2') * 3 + 'a' + i));%0A            %7D%0A        %7D%0A        if (digit == '7') %7B%0A            characters.add('s');%0A        %7D else if (digit == '8') %7B%0A            for (char c = 't'; c %3C= 'v'; c++) %7B%0A                characters.add(c);%0A            %7D%0A        %7D else if (digit == '9') %7B%0A            for (char c = 'w'; c %3C= 'z'; c++) %7B%0A                characters.add(c);%0A            %7D%0A        %7D%0A        return characters;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Solution solution = new Solution();%0A//        for (int i = 0; i %3C 10; i++) %7B%0A//            List%3CCharacter%3E characters = solution.allLetters((char) ('1' + i));%0A//            System.out.print(i + %22:%22);%0A//            for (Character c : characters) %7B%0A//                System.out.print(c);%0A//            %7D%0A//            System.out.println();%0A//        %7D%0A        for (String str : solution.letterCombinations(%2223%22)) %7B%0A            System.out.println(str);%0A        %7D%0A    %7D%0A%7D

solve 17