public int ladderLength(String start, String end, HashSet<String> dict) {
        // Start typing your Java solution below
        // DO NOT write main() function
        if (start.equals(end)) return 0; //if start == end, length = 0;
        //add both start and end into dict
        if (!dict.contains(start)) dict.add(start); 
        if (!dict.contains(end)) dict.add(end);
        
        //LinkedList for a Queue
        LinkedList<String> q = new LinkedList<String>(); //need <String>!!!
        q.add(start); //put start into Queue
        dict.remove(start); //remove start from dict
        
        //Hashtable for store length from start
        Hashtable<String, Integer> dists = new Hashtable<String, Integer>(); //no primitive type!!!
        dists.put(start, 0); //length of start to start is zero

        while (q.size() != 0) {
            //retrieve each word by word from Queue
            String word = q.remove();
            int length = dists.get(word); //length of current word from start
            
            /**
             * List all words that only one character differs from the dequeued word
             * compare the words with the words one by one
             */
            String[] words = getWords(word);
            for (int i = 0; i < words.length; i++) {
            	if (dict.remove(words[i])) { //check if word exists in dict and remove the contained word at the same time
            		if (words[i].equals(end)) return length+2; //if found end return length plus 2
            		dists.put(words[i], length+1); //put new length into hash map
            		q.add(words[i]); //enqueue new word from dict
            	}
            }
            
//            //for each word retrieved from Queue, check all words in dict
//            //if a word is connected to the retrieved word, add it into Queue
//            //update its length into Hashtable
//            //remove it from dict
//            Iterator<String> it = dict.iterator();
//            while (it.hasNext()) {
//                String nextWord = it.next();
//                
//                if (isConnected(word, nextWord)) {
//                    //int dist = dists.get(word) + 1;
//                    if (nextWord.equals(end)) return length+2;
//                    dists.put(nextWord, length+1);
//                    it.remove();
//                    //dict.remove(nextWord);
//                    q.add(nextWord);
//                }
//            }
        }
        return 0;
    }