leetcode Letter Combinations of a Phone Number

题目链接

public class Solution {
    static String[] map = new String[10];




    public   List<String> letterCombinations(String digits) {
        map[0] = "";
        map[1] = "";
        map[2] = "abc";
        map[3] = "def";
        map[4] = "ghi";
        map[5] = "jkl";
        map[6] = "mno";
        map[7] = "pqrs";
        map[8] = "tuv";
        map[9] = "wxyz";
        return help(digits, 0);
    }

    public List<String> help(String digits,int start)
    {
        List<String> result=new LinkedList<String>();
        if(start<digits.length())
        {

            String array=map[digits.charAt(start)-'0'];
            List<String> temp=help(digits, start+1);
            if(temp.isEmpty())
            {
                for(int i=0;i<array.length();i++)
                {
                    result.add(""+array.charAt(i));
                }



            }
            else
            {
                for(int i=0;i<array.length();i++)
                {
                    for (String string : temp) {
                        result.add(""+array.charAt(i)+string);
                    }
                }
            }


        }

        return result;
    }
}

你可能感兴趣的:(leetcode Letter Combinations of a Phone Number)