81. Surrounded Region
Medium
A matrix contains X and O. Return a copy where each O that does not touch the border and is not connected to an O on the border is changed to X. Connections are only through the sides.
Example 1
Input: tabuleiro = [["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"]]
Example 2
Input: tabuleiro = [["O","O"],["O","O"]]
Output: [["O","O"],["O","O"]]
Constraints
- 1 <= linhas, colunas <= 200
- A matriz contém apenas "X" e "O".
GraphsDFSMatrix
Saved in this browser
Caso 1
tabuleiro =
[["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]
Expected =
[["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]]
Caso 2
tabuleiro =
[["O","O"],["O","O"]]
Expected =
[["O","O"],["O","O"]]
Run checks these 2 cases. Submit runs all 6, including hidden ones.