mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给你一个大小为 <code>m x n</code> ,由若干 <code>0</code> 和 <code>1</code> 组成的二维网格 <code>grid</code> ,其中 <code>1</code> 表示陆地, <code>0</code> 表示水。<strong>岛屿</strong> 由水平方向或竖直方向上相邻的 <code>1</code> (陆地)连接形成。</p>
 | 
						||
 | 
						||
<p>如果 <strong>恰好只有一座岛屿 </strong>,则认为陆地是 <strong>连通的</strong> ;否则,陆地就是 <strong>分离的</strong> 。</p>
 | 
						||
 | 
						||
<p>一天内,可以将 <strong>任何单个</strong> 陆地单元(<code>1</code>)更改为水单元(<code>0</code>)。</p>
 | 
						||
 | 
						||
<p>返回使陆地分离的最少天数。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong class="example">示例 1:</strong></p>
 | 
						||
<img alt="" src="https://assets.leetcode.com/uploads/2021/12/24/land1.jpg" style="width: 500px; height: 169px;" />
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>grid = [[0,1,1,0],[0,1,1,0],[0,0,0,0]]
 | 
						||
<strong>输出:</strong>2
 | 
						||
<strong>解释:</strong>至少需要 2 天才能得到分离的陆地。
 | 
						||
将陆地 grid[1][1] 和 grid[0][2] 更改为水,得到两个分离的岛屿。</pre>
 | 
						||
 | 
						||
<p><strong class="example">示例 2:</strong></p>
 | 
						||
<img alt="" src="https://assets.leetcode.com/uploads/2021/12/24/land2.jpg" style="width: 404px; height: 85px;" />
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>grid = [[1,1]]
 | 
						||
<strong>输出:</strong>2
 | 
						||
<strong>解释:</strong>如果网格中都是水,也认为是分离的 ([[1,1]] -> [[0,0]]),0 岛屿。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>m == grid.length</code></li>
 | 
						||
	<li><code>n == grid[i].length</code></li>
 | 
						||
	<li><code>1 <= m, n <= 30</code></li>
 | 
						||
	<li><code>grid[i][j]</code> 为 <code>0</code> 或 <code>1</code></li>
 | 
						||
</ul>
 |