grid is a map of 1 (land) and 0 (water). An island is a group of land cells connected up, down, left or right. Return the number of islands.
For [[1, 1, 0], [0, 1, 0], [0, 0, 1]] the answer is 2.
Example 1
Input:
num_islands([[1, 1, 0], [0, 1, 0], [0, 0, 1]])
Output:
2
Example 2
Input:
num_islands([[0, 0], [0, 0]])
Output:
0
0 <= rows, cols <= 3000 or 1.No results yet
Run your code to check it against the examples, or submit to run every test.