first thought
- the same as maze II, using BFS.
- need to record the path, and update the path at proper time.
- there’s no need to iterate when the ball reach the hole.
solution
|
|
problem
wrong answer
reason
there’s one mistake in checking the order of paths.
modification
|
|
change to12345678910char c1 = newPoint.path.charAt(k);char c2 = newPath.charAt(k);if (c1 < c2) { updated = true; break;} else if (newPoint.path.charAt(k) > newPath.charAt(k)) { updated = true; newPoint.path = newPath; break;}
problem
wrong answer
input:
[[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]]
[4,3]
[0,1]
Your answer
“lu”
Expected answer
“lul”
reason
- dirX, dirY are wrong.
- there’s a method in String to compare two strings.
modification
|
|
problem
still wrong answer…
reason
when newPoint.dis == dis, it should re-put the point to the queue because although the dis is the same, the path is updated.
modification
|
|