mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			34 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>Given an <code>m x n</code> matrix <code>board</code> containing <code>'X'</code> and <code>'O'</code>, <em>capture all regions that are 4-directionally surrounded by</em> <code>'X'</code>.</p>
 | 
						|
 | 
						|
<p>A region is <strong>captured</strong> by flipping all <code>'O'</code>s into <code>'X'</code>s in that surrounded region.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/xogrid.jpg" style="width: 550px; height: 237px;" />
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]
 | 
						|
<strong>Output:</strong> [["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]]
 | 
						|
<strong>Explanation:</strong> Notice that an 'O' should not be flipped if:
 | 
						|
- It is on the border, or
 | 
						|
- It is adjacent to an 'O' that should not be flipped.
 | 
						|
The bottom 'O' is on the border, so it is not flipped.
 | 
						|
The other three 'O' form a surrounded region, so they are flipped.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> board = [["X"]]
 | 
						|
<strong>Output:</strong> [["X"]]
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>m == board.length</code></li>
 | 
						|
	<li><code>n == board[i].length</code></li>
 | 
						|
	<li><code>1 <= m, n <= 200</code></li>
 | 
						|
	<li><code>board[i][j]</code> is <code>'X'</code> or <code>'O'</code>.</li>
 | 
						|
</ul>
 |