Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    130 - Surrounded Regions.

    Medium

    Given an m x n matrix board containing 'X' and 'O', capture all regions that are 4-directionally surrounded by 'X'.

    A region is captured by flipping all 'O's into 'X's in that surrounded region.

    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: Notice that an 'O' should not be flipped if:

    • It is on the border, or

    • It is adjacent to an 'O' that should not be flipped.

    The bottom 'O' is on the border, so it is not flipped.

    The other three 'O' form a surrounded region, so they are flipped.

    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'.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Unit solve(Array<CharArray> board)
      final Unit dfs(Array<CharArray> board, Integer row, Integer column)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait