Linkage
https://leetcode.com/problems/word-ladder/description/
Naive Code
In the naive implementation, we will consider all words as the node in graph, then using BFS to record the shortest depth. Once we visit endWord, then we return the current depth.
1 | import java.util.Queue; |
Improve Code
In the naive implementation. each time to find the next word on the chain ,we need to traverse all the node in the all graph, which is time-consuming(The test cases improve this). The wiser way is to dectect new node by substitute each letter in the current word,(The consumed time is word_length*26)
1 | import java.util.Queue; |