170. Surrounded Regions
Medium · Graph
Given an m × n board containing 'X' and 'O' characters, capture all 'O' regions that are surrounded by 'X'. A region of 'O's is surrounded if it cannot reach the boundary of the board. All 'O's that are not surrounded should remain 'O', and all surrounded 'O's should be replaced with 'X'.
You must modify the board in-place.
Examples
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: The 'O' at position (3,1) is not surrounded because it can reach the boundary. All other 'O's are surrounded by 'X' and are captured.
Example 2 Input: board = [['X']] Output: [['X']] Explanation: A single cell board with no 'O's remains unchanged.
Constraints
- Standard input/output constraints apply