A coastline was mapped twice. before and after are grids of the same size where 1 is land and
0 is water. An island of after is a maximal group of land cells connected up, down, left or
right. Such an island survives if every one of its cells is also land in before.
Return the number of islands of after that survive.
Examples
Input: before = [[1,1,0], after = [[1,1,0],
[0,1,0], [0,0,0],
[1,0,1]] [1,1,1]]
Output: 1
Explanation: the island {(0,0),(0,1)} is land in `before` too. The bottom island
{(2,0),(2,1),(2,2)} contains (2,1), which was water in `before`.
Input: before = [[0,1], after = [[1,1],
[1,1]] [1,1]]
Output: 0
Explanation: one island, and its cell (0,0) was water before.
Input: before = [[1]], after = [[1]]
Output: 1
Constraints
1 <= rows, cols <= 80; both grids have the same shape.- Target
O(rows * cols)time.
Goals
- Flood-fill each island of one grid while checking a second grid
- Finish exploring an island even after it has been disqualified