public static int ladderLength2(String start, String end, Set<String> dict) {
    	List<String> nodes = new ArrayList<String>();
    	nodes.add(start);
    	nodes.add(end);
    	for (String val : dict) {
    		if (!nodes.contains(val)) nodes.add(val);
    	}
    	List<GraphNode> graph = generateGraph(nodes);
    	//print(graph.get(0));
    	GraphNode snode = graph.get(0);
    	GraphNode enode = graph.get(1);
    	List<GraphNode> stack = new ArrayList<GraphNode>();
    	stack.add(snode);
    	int b = 0, e = 0;
    	int step = 0;
    	while (true) {
    		int endnode = e + 1;
    		for (int i = b; i < endnode; i++) {
    			GraphNode cnode = stack.get(i);
    			for (GraphNode n : cnode.neighbors) {
    				if (n == enode) return step + 1;
    				else if (!stack.contains(n)) {
    					stack.add(n);
    					e = e + 1;
    				}
    			}
    		}
    		if (b == e) {
    			break;
    		}
    		step = step + 1;
    		b = endnode;
    	}
    	return -1;
    }