first thought
- have no idea…
- it can be also solved by dfs, but I think bfs cost less, so just use bfs.
- Have seen the answer. Because the problem is to delete minimum count of chars, so the root is the whole string, the neighbors is all the strings that deleted by one char.
solution
|
|
problem
wrong answer, there’s a empty string in the result.
Input:
“x(“
Output:
[“x”,””]
Expected:
[“x”]
reason
although have checked hasValid, but it still can be some smaller strings were added into the queue. (e.g first string is not valid, it’s children are added, the second string is valid, the rest substring will not be added. But the substring of the first one has already be added, so there would be some shorter but valid results.
modification
avoid the shorter cases.
|
|