https://oj.leetcode.com/problems/word-ladder-ii/
http://blog.csdn.net/linhuanmars/article/details/23071455
public class solution { public list<list<string>> Findladders (string start, string end, set<string> dict) { list<list<string>> toreturn = new ArrayList<> (); Queue<Node> queue = new LinkedList<> (); queue.offer (New node (start, new arraylist<string> ())); int minlen = -1; Set<String> visited = new HashSet<> (); visited.add (StART); while (!queue.isempty ()) { node node = queue.poll (); if (Node.str.equals (end)) { if (minlen == -1) { toreturn.add (Node.path); minlen = Node.path.size (); } else if ( Node.path.size () == minlen) { toreturn.add (Node.path); } } else { visited.add (NODE.STR); &nbsP; list<node> nextnodes = next (node, dict, visited); for (node Nextnode : nextnodes) queue.offer (NextNode); } } return toReturn; } private List<Node> next (node from, set<string> dict, set<string> visited) { list<node> toreturn = new ArrayList<> (&NBSP;&NBS);p; char[] chars = from.str.tochararray (); for (int i = 0 ; i < chars.length ; i ++) { char oric = chars[i]; for (char c = ' A ' ; c <= ' z ' ; c ++) { if (c == oric) continue; chars[i] = c; string str = new string (chars); if (Dict.contains (str ) && !visited.contains (str)) { toreturn.add (New node (str, from.path)); } } chars[i] = oric; } return toreturn; } private static class Node { string str; list <string> path; node (String str, List< String> oldpath) { this.str = str; path = new ArrayList<> (OldPath); path.add (str); } }}
[leetcode]126 Word Ladder II