Given a 2D board containing 'X'
and 'O'
, capture all regions surrounded by 'X'
.
A region is captured by flipping all 'O'
s into 'X'
s in that surrounded region.
Analysis: This question is quite similar to the problem of number of islands. we need to merge ''O" from the boarder, so that we can count the number of the islands. and then replace the ''O
Here is a good code for this question
http://www.jyuan92.com/blog/leetcode-surrounded-regions/\
For example,
X X X X X O O X X X O X X O X X
After running your function, the board should be:
X X X X X X X X X X X X X O X X