前面一周都在憋论文,终于到昨天出了一版,虽然还有很多工作要做,也准备要休息两天再改了。今天试着写了几道面试题,有段时间没有写代码了,生疏很多了,这里记录一下用golang解决wordladder这道题吧。
这道题理解很简单,
Given two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that:
Only one letter can be changed at a time
Each intermediate word must exist in the word list
For example,
Given:
beginWord = “hit”
endWord = “cog”
wordList = [“hot”,”dot”,”dog”,”lot”,”log”]
As one shortest transformation is “hit” -> “hot” -> “dot” -> “dog” -> “cog”,
return its length 5.
Note:
Return 0 if there is no such transformation sequence.
All words have the same length.
All words contain only lowercase alphabetic characters.