Question about 18.7 java

#1

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.

0 Likes

#2

Should have searched on the forum before posting :slight_smile:
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

#3

Still good for you to report that, thanks @ray!

0 Likes