leetcode: Surrounded Regions
Given a 2D board containing
'O', capture all regions surrounded by
A region is captured by flipping all
'X's in that surrounded region .
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
Solution and Precautions:
Scan the four edges of the given matrix, if encounter any ’0′, then start from this ’0′ use either BFS or DFS to mark all the connected ’0′ area by some marks say ‘#’, after doing this, all the cells with ‘#’ mark should remain to be ’0′ while other cells should be set ‘X’ no matter what it previously was.
Tips and Divergent thinking:
（转载本站文章请注明作者和出处 烟客旅人 sigmainfy — http://www.sigmainfy.com，请勿用于任何商业用途）