With the solution’s code, as long as the ending string is in the dictionary, it outputs -1, which is wrong. Run the test with s = “cat”, t=“bat” and dictionary = {“cat”, “bat”}. The result is supposed to be 1. But the code yields -1.
Question about 18.7 java
ray
#2
Should have searched on the forum before posting
It’s been discussed that the right code should be
if (visited.contains(modStr)) {
visited.remove(modStr);
q.add(new StringWithDistance(modStr, f.distance + 1));
}
0 Likes