Leetcode Problem 130. Surrounded Regions
130. Surrounded Regions
AI Mock Interview
Leetcode Solutions
DFS (Depth-First Search) Approach
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Iterate over the border cells of the board.
For each 'O' cell on the border, perform a DFS traversal to mark all connected 'O' cells as 'E'.
After marking, iterate over the entire board.
For each cell, if it is 'O', change it to 'X' (captured); if it is 'E', revert it to 'O' (escaped).
The board is now updated with all captured regions filled with 'X'.
BFS (Breadth-First Search) Approach
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...