input: Write a function to count the number of islands in a given grid.
  assert countIslands([[True, True, False, False, False], [False, True, False, False, True], [True, False, False, True, True], [False, False, False, False, False], [True, False, True, False, True]]) == 6
  assert countIslands([[True, True, True], [True, False, True], [True, True, True]]) == 1
  assert countIslands([[False, False, False], [False, False, False], [False, False, False]]) == 0
output: def countIslands(grid):
      if not grid:
          return 0
  
      rows, cols = len(grid), len(grid[0])
      visited = [[False] * cols for _ in range(rows)]
  
      def dfs(r, c):
          if r < 0 or c < 0 or r >= rows or c >= cols or visited[r][c] or not grid[r][c]:
              return
          visited[r][c] = True
          dfs(r + 1, c)
          dfs(r - 1, c)
          dfs(r, c + 1)
          dfs(r, c - 1)
  
      count = 0
      for r in range(rows):
          for c in range(cols):
              if grid[r][c] and not visited[r][c]:
                  dfs(r, c)
                  count += 1
  
      return count