Class Solution
java.lang.Object
g1501_1600.s1568_minimum_number_of_days_to_disconnect_island.Solution
1568 - Minimum Number of Days to Disconnect Island.<p>Hard</p>
<p>You are given an <code>m x n</code> binary grid <code>grid</code> where <code>1</code> represents land and <code>0</code> represents water. An <strong>island</strong> is a maximal <strong>4-directionally</strong> (horizontal or vertical) connected group of <code>1</code>’s.</p>
<p>The grid is said to be <strong>connected</strong> if we have <strong>exactly one island</strong> , otherwise is said <strong>disconnected</strong>.</p>
<p>In one day, we are allowed to change <strong>any</strong> single land cell <code>(1)</code> into a water cell <code>(0)</code>.</p>
<p>Return <em>the minimum number of days to disconnect the grid</em>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/12/24/land1.jpg" alt="" /></p>
<p><strong>Input:</strong> grid = [[0,1,1,0],[0,1,1,0],[0,0,0,0]]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> We need at least 2 days to get a disconnected grid. Change land grid[1][1] and grid[0][2] to water and get 2 disconnected island.</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/12/24/land2.jpg" alt="" /></p>
<p><strong>Input:</strong> grid = [[1,1]]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> Grid of full water is also disconnected (<a href="1,1">1,1</a> -> <a href="0,0">0,0</a>), 0 islands.</p>
<p><strong>Constraints:</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> is either <code>0</code> or <code>1</code>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minDays
public int minDays(int[][] grid)
-