java solution
class Solution {
public int ladderLength(String beginWord, String endWord, List<String> wordList) {
//首先根据wordList来创建一个集合
HashSet<String> wordSet = new HashSet<>(wordList);
if(!wordSet.contains(endWord)) return 0; //如果endWord都不存在于wordList, 那么说明无法到达终点
//开始BFS过程,首先创建需要的数据结构
Queue<String> queue = new LinkedList<>();
queue.add(beginWord);
Set