Word Ladder I和Word Ladder II两道题给我们的经验:
- It’s much faster than one-end search indeed as explained in wiki.
- BFS isn’t equivalent to Queue. Sometimes Set is more accurate representation for nodes of level. (also handy since we need to check if we meet from two ends)
- It’s safe to share a visited set for both ends since if they meet same string it terminates early. (vis is useful since we cannot remove word from dict due to bidirectional search)
- It seems like if(set.add()) is a little slower than if(!contains()) then add() but it’s more concise.