Class Solution
- java.lang.Object
-
- g1501_1600.s1568_minimum_number_of_days_to_disconnect_island.Solution
-
public class Solution extends Object
1568 - Minimum Number of Days to Disconnect Island.Hard
You are given an
m x nbinary gridgridwhere1represents land and0represents water. An island is a maximal 4-directionally (horizontal or vertical) connected group of1’s.The grid is said to be connected if we have exactly one island , otherwise is said disconnected.
In one day, we are allowed to change any single land cell
(1)into a water cell(0).Return the minimum number of days to disconnect the grid.
Example 1:

Input: grid = [[0,1,1,0],[0,1,1,0],[0,0,0,0]]
Output: 2
Explanation: 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.
Example 2:

Input: grid = [[1,1]]
Output: 2
Explanation: Grid of full water is also disconnected (1,1 -> 0,0), 0 islands.
Constraints:
m == grid.lengthn == grid[i].length1 <= m, n <= 30grid[i][j]is either0or1.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-