You are given an m x n matrix board containing letters βXβ and βOβ, capture regions that are surrounded:
- Connect: A cell is connected to adjacent cells horizontally or vertically.
- Region: To form a region connect every βOβ cell.
- Surround: The region is surrounded with βXβ cells if you can connect the region with βXβ cells and none of the region cells are on the edge of the board.
A surrounded region is captured by replacing all βOβs with βXβs in the input matrix board.
Example 1:
- 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β]]
- Explanation:
In the above diagram, the bottom region is not captured because it is on the edge of the board and cannot be surrounded.
Example 2:
- Input: board = [[βXβ]]
- Output: [[βXβ]]
Constraints:
- m == board.length
- n == board[i].length
- 1 <= m, n <= 200
- board[i][j] is βXβ or βOβ.