public List<List<String>> findLadders(String beginWord, String endWord, Set<String> wordList) {
        if (beginWord == null || endWord == null || wordList == null) return null;
        Queue<String> q = new LinkedList<String>();
        HashMap<String, Integer> distance = new HashMap<String, Integer>();
        HashMap<String, List<String>> backtrack = new HashMap<String, List<String>>();
        List<List<String>> result = new LinkedList<List<String>>();
        q.add(beginWord);
        distance.put(beginWord, 1);
        while (!q.isEmpty()) {
            String curr = q.remove();
            for (String next : expand(curr, wordList)) {
                if (!distance.containsKey(next)) {
                    distance.put(next, distance.get(curr) + 1);
                    q.add(next);
                }
                if (!backtrack.containsKey(next)) {
                    backtrack.put(next, new LinkedList<String>());
                }
                backtrack.get(next).add(curr);
            }
        }
        buildResult(endWord, beginWord, new LinkedList<String>(), result, distance, backtrack);
        return result;
    }