Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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

posted on 2014-08-13 07:30  Tonix  阅读(154)  评论(0编辑  收藏  举报