My AC Java Solution


  • 1
    N
    String[] num = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    public List<String> letterCombinations(String digits) {
        List<String> returnList = new ArrayList<String>();
        if (digits == null || digits.length() == 0) return returnList;
        List<String> list = letterCombinations(digits.substring(1));
        for (int i = 0; i < num[digits.charAt(0) - '0' - 2].length(); i++) {
            if (list.size() == 0) {
                returnList.add("" + num[digits.charAt(0) - '0' - 2].charAt(i));
            } else {
                for (int j = 0; j < list.size(); j++) {
                    returnList.add(num[digits.charAt(0) - '0' - 2].charAt(i) + list.get(j));
                }
            }
        }
        return returnList;
    }

  • 0
    A

    really graceful


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.