@@ -0,0 +1,2164 @@
+import java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.HashSet;%0Aimport java.util.LinkedList;%0Aimport java.util.List;%0Aimport java.util.Queue;%0A%0Apublic class LeetCode0127 %7B%0A    class Node %7B%0A        String str;%0A        int level;%0A        Node parent;%0A%0A        public Node(String str, int level, Node parent) %7B%0A            this.str = str;%0A            this.level = level;%0A            this.parent = parent;%0A        %7D%0A    %7D%0A%0A    public int ladderLength(String beginWord, String endWord, List%3CString%3E wordList) %7B%0A        if (wordList == null %7C%7C wordList.size() == 0) %7B%0A            return 0;%0A        %7D%0A%0A        Queue%3CNode%3E queue = new LinkedList%3CNode%3E();%0A        queue.add(new Node(beginWord, 1, null));%0A%0A        HashSet%3CString%3E visited = new HashSet%3CString%3E();%0A        HashSet%3CString%3E unvisited = new HashSet%3CString%3E();%0A        unvisited.addAll(wordList);%0A%0A        int preLevel = 0;%0A%0A        while (!queue.isEmpty()) %7B%0A            Node node = queue.poll();%0A%0A            if (endWord.equals(node.str)) %7B%0A                Node p = node;%0A                return p.level;%0A            %7D%0A%0A            if (preLevel %3C node.level) %7B%0A                preLevel = node.level;%0A                unvisited.removeAll(visited);%0A            %7D%0A%0A            char%5B%5D arr = node.str.toCharArray();%0A            for (int i = 0; i %3C arr.length; i++) %7B%0A                char c = arr%5Bi%5D;%0A                for (char j = 'a'; j %3C= 'z'; j++) %7B%0A                    arr%5Bi%5D = j;%0A                    String newStr = new String(arr);%0A                    if (!unvisited.contains(newStr)) %7B%0A                        continue;%0A                    %7D%0A                    visited.add(newStr);%0A                    Node newNode = new Node(newStr, node.level + 1, node);%0A                    queue.offer(newNode);%0A                %7D%0A                arr%5Bi%5D = c;%0A            %7D%0A        %7D%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        LeetCode0127 leetcode = new LeetCode0127();%0A        List%3CString%3E wordList = new ArrayList%3CString%3E(%0A            Arrays.asList(%22hot%22, %22dot%22, %22dog%22, %22lot%22, %22log%22, %22cog%22));%0A        System.out.println(leetcode.ladderLength(%22hit%22, %22cog%22, wordList));%0A    %7D%0A%7D

Add LeetCode0127.java