Word Ladder II


Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end.
Solution: My thought is to use BFS and use additional vectors to store the paths. Following code passes small judge but got "Memory limit exceeded" error for large judge. The main reason is I did not mark the visited node for current path.
Thank ppgame for providing the following solution which passes the large judge. The key difference is to use hash set to mark the node, and then use iterators to track the path.
 

Comments

Popular posts from this blog

Maximum Gap

[ITint5] Maximum Subarray for a Circular Array

[CC150] Chapter 4 Trees and Graphs