首页 > 代码库 > LeetCode "Word Ladder" - TRICKY
LeetCode "Word Ladder" - TRICKY
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