1class Solution {2public int ladderLength(String beginWord, String endWord, List<String> wordList) {3int count = 1;4Set<String> words = new HashSet<>(wordList);5Queue<String> q = new LinkedList<String>();6q.add(beginWord);78while (!q.isEmpty()) {9int size = q.size();1011while (size-- > 0) {12String word = q.poll();13char[] chList = word.toCharArray();1415for (int i = 0; i < word.length(); i++) {16char tmp = chList[i];1718for (char c = 'a'; c <= 'z'; c++) {19chList[i] = c;20String newWord = new String(chList);2122if (words.contains(newWord)) {23if (newWord.equals(endWord)) {24return count + 1;25}26q.add(newWord);27words.remove(newWord);28}29}3031chList[i] = tmp;32}33}3435count++;36}3738return 0;39}40}