489. Robot Room Cleaner

https://en.wikipedia.org/wiki/Maze-solving_algorithm#Wall_follower

1.本題還是要 4 個方向, why? 因為還是得要知道有沒有走過某個 cell, 這題 visited 用 HashSet<String> 比較方便

move 只能提供是不是碰到 wall 的資訊

方向要訂正確, 東南西北, 因為我們總是 turnright, 順時針

2. 真的能走時, 走完 dfs, 要 backtracking

3.

turnRight() 寫在最後

所以其實是先 move()

如果不能 move(), 或走過了, 才要 turnRight()

Last updated

Was this helpful?