It is not as easy as I thought it to be, mostly because of time\space limitation. And actually that's the punch line of this problem
My intuition was DFS. I got several failing attemption - all TLE or MLE. Since what we are supposed to find is 'shortest', BFS is definitely better than DFS: DFS exausts all paths but BFS doesn't! And that's not the end - think about the case that dictonary is huge, and here comes the 2nd important trick: we don't iterate dictionary to find children, instead we literally change a string by 26 chars one by one, and slot by slot.
Please mind these tricks - i spent hours in the snare but finally i got out of it and i think it deserves!
Check it here: http://zhaohongze.com/wordpress/2013/12/11/leetcode-word-ladder/
And also, another neat idea of Double BFS is here: http://yucoding.blogspot.com/2013/08/leetcode-question-127-word-ladder.html
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步