Graph BFS / DFS
LC #130Medium
Surrounded Regions
Graph BFS / DFS
Problem
Capture all regions of 'O' surrounded by 'X'. A region is captured by flipping all 'O's into 'X's.
matrixdfsbfs
Constraints
- ›1 ≤ m, n ≤ 200
- ›board[i][j] is 'X' or 'O'.
Example
Input
board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]Output
[["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]]Why
The bottom 'O' is on the boundary, so it is not captured. The inner 'O's are captured.