public int ladderLength(String beginWord, String endWord, Set<String> wordDict) {
        Queue<String> queue = new LinkedList<String>();
        HashSet<String> hashSet = new HashSet<String>();
        for (String s : wordDict)
            hashSet.add(s);
        queue.add(beginWord);
        hashSet.add(endWord);
        int step = 0;
        while (!queue.isEmpty()) {
            int size = queue.size();
            ++step;
            while (size-- > 0) {
                String curString = queue.poll();
                if (curString.equals(endWord))
                    return step;
                char[] strArray = curString.toCharArray();
                for (int i = 0; i < beginWord.length(); ++i) {
                    for (char c = 'a'; c <= 'z'; ++c) {
                        char temp = strArray[i];
                        strArray[i] = c;
                        String newString = String.copyValueOf(strArray);
                        strArray[i] = temp;
                        if (hashSet.contains(newString)) {
                            queue.offer(newString);
                            hashSet.remove(newString);
                        }
                    }
                }
            }
        }
        return 0;
    }