首页 > 其他 > 详细

LeetCode "Word Ladder" - TRICKY

时间:2014-08-13 08:00:25      阅读:322      评论:0      收藏:0      [点我收藏+]

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

LeetCode "Word Ladder" - TRICKY,布布扣,bubuko.com

LeetCode "Word Ladder" - TRICKY

原文:http://www.cnblogs.com/tonix/p/3909116.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!