This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public int numIslands(char[][] grid) { | |
int count = 0; // initialize the count to 0 | |
if (grid.length == 0) { // if the grid is empty, return 0 | |
return 0; | |
} | |
// iterate through each cell in the grid | |
for (int i = 0; i < grid.length; i++) { | |
for (int j = 0; j < grid[i].length; j++) { | |
// if a land cell (1) is found, increment the count |