Swap the result queue


  • 0
    D

    public List<String> letterCombinations(String digits) {
    char[][] dict = {{'0'}, {'1'}, {'a', 'b', 'c'}, {'d', 'e', 'f'},
    {'g', 'h', 'i'}, {'j', 'k', 'l'}, {'m', 'n', 'o'},
    {'p', 'q', 'r', 's'}, {'t', 'u', 'v'}, {'w', 'x', 'y', 'z'}, };

        List<String> result = new ArrayList(); 
        result.add("");
        for (int i = 0; i < digits.length(); i++) {
            List<String> temp = new ArrayList();
            for (char c : dict[digits.charAt(i) - '0']) {
                for (String s : result) {
                    temp.add(s+c);
                }
            }
            result = temp;
        }
        return result.size() == 1 ? new ArrayList() : result;
    }

Log in to reply
 

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