Surrounded Regions

You are given an m x n matrix board containing letters 'X' and 'O'. Capture regions that are surrounded: Connect every 'O' cell with adjacent cells horizontally or vertically to form regions. A region is surrounded by '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 in it with 'X's.

Constraints

  • m == board.length
  • n == board[i].length
  • 1 <= m, n <= 200
  • board[i][j] is 'X' or 'O'.
Saving… · 2 lines
class Solution:
def surroundedRegions(self, board: List[List[str]]) -> None:
Console

Click Run to execute sample tests.