dfs
traversing string ,and split it one char by next, if find the splited left word in dict, recursiving the remaining right substring. in this way, it will make sure find a solution, but also traversing all unnecessary possibilites. and need design a class variable to stop the dfs()
|
|
bfs
as mentioned above, dfs
goes to all possibile branches, which is not required. bfs
is like a greedy way, to find out one working solution and done.
also need keep track of searched left sub-strings, since the remaining right sub-strings may can not find a matched from dict, then the left sub-string is not acceptable, so the left sub-string need move one char further.
|
|
this bfs
is not good design.
a pretty simple sample code