Count the islands
Mediumgraphdfsbfsmatrix
A sea map: each row is a string of "1" (land) and "0" (water). An island is land cells connected horizontally or vertically (not diagonally). Return the number of islands.
Example 1
Input: grid = ["11110","11010","11000","00000"] Output: 1
Example 2
Input: grid = ["11000","11000","00100","00011"] Output: 3
Constraints
- 0 ≤ rows, columns ≤ 300
- Each cell is '0' or '1'
Submit checks your solution against 8 tests, including hidden ones.
/**
* @param {string[]} grid
* @return {int}
*/
function numIslands(grid) {
}