input: Write a python function to count the number of islands in a given grid.
  assert countIslands([[1, 1, 0, 0, 0], [0, 1, 0, 0, 1], [1, 0, 0, 1, 1], [0, 0, 0, 0, 0], [1, 0, 1, 0, 1]]) == 5
  assert countIslands([[1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1]]) == 2
  assert countIslands([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 0
output: def countIslands(grid):
      if not grid:
          return 0
  
      def dfs(grid, i, j):
          if i < 0 or i >= len(grid) or j < 0 or j >= len(grid[0]) or grid[i][j] == 0:
              return
          grid[i][j] = 0  # Mark the cell as visited by setting it to 0
          dfs(grid, i+1, j)
          dfs(grid, i-1, j)
          dfs(grid, i, j+1)
          dfs(grid, i, j-1)
  
      num_islands = 0
      for i in range(len(grid)):
          for j in range(len(grid[0])):
              if grid[i][j] == 1:
                  num_islands += 1
                  dfs(grid, i, j)
  
      return num_islands