public static ArrayList<String> letterCombinations(String digits) {
        ArrayList<String> result = new ArrayList<String>();
        if (digits.isEmpty()) {     // no digit
            result.add("");
            return result;
        }
        int n = digits.length();
        Queue<String> queue = new LinkedList<String>();
        for (int i = 0; i < n; i++) {
            String seq = letters[digits.charAt(i)-'0']; // the letter sequence related to the given digit
            int m = seq.length();
            if (queue.peek() == null) {         // Empty queue; no digit has been processed before
                for (int j = 0; j < m; j++)     // Put separate letters into the queue
                    queue.offer(""+seq.charAt(j));
            } else {
                Queue<String> temp = new LinkedList<String>();
                String s;
                // For each string in the queue, concatenate it with each letter in the sequence,
                // and put the concatenated string into a new queue
                while ((s = queue.poll()) != null) {
                    for (int j = 0; j < m; j++)
                        temp.offer(s+seq.charAt(j));
                }
                queue = temp;
            }
        }
        result = new ArrayList<String>(queue);  // Make result an ArrayList from the queue
        return result;
    }