Number of Islands in Three Dimensions
Problem statement
grid[z][r][c] is 1 for land and 0 for water. Land cells belong to the same island when connected through shared faces along depth, row, or column axes. Return the number of islands.
Function
numIslands3D(grid: int[][][]) → intExamples
Example 1
grid = [[[1,0],[0,1]],[[1,0],[0,0]]]return = 2The two cells at [0,0,0] and [1,0,0] connect by a face; the diagonal cell is separate.
Constraints
- The rectangular 3D grid contains at most
10^6cells.