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 0
    grid[i][j] = "0"
    dfs(grid,i+1,j)
    dfs(grid,i,j+1)
    dfs(grid,i-1,j)
    dfs(grid,i,j-1)
    return 1

def numIslands(grid):
    nums=0
    for i in range(len(grid)):
        for j in range(len(grid[0])):
            if grid[i][j] == "1":
                numIslands+=dfs(grid,i,j)
    return nums

print(numIslands([["1","1","1","1","0"],["1","1","0","1","0"],["1","1","0","0","0"],["0","0","0","0","0"]]))

e3a556995f5678b1c3cadd9a1dbe34fb7a239af5
<mask token>

<mask token>


def numIslands(grid):
    nums = 0
    for i in range(len(grid)):
        for j in range(len(grid[0])):
            if grid[i][j] == '1':
                numIslands += dfs(grid, i, j)
    return nums


<mask token>

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 0
    grid[i][j] = '0'
    dfs(grid, i + 1, j)
    dfs(grid, i, j + 1)
    dfs(grid, i - 1, j)
    dfs(grid, i, j - 1)
    return 1


def numIslands(grid):
    nums = 0
    for i in range(len(grid)):
        for j in range(len(grid[0])):
            if grid[i][j] == '1':
                numIslands += dfs(grid, i, j)
    return nums


<mask token>

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 0
    grid[i][j] = '0'
    dfs(grid, i + 1, j)
    dfs(grid, i, j + 1)
    dfs(grid, i - 1, j)
    dfs(grid, i, j - 1)
    return 1


def numIslands(grid):
    nums = 0
    for i in range(len(grid)):
        for j in range(len(grid[0])):
            if grid[i][j] == '1':
                numIslands += dfs(grid, i, j)
    return nums


print(numIslands([['1', '1', '1', '1', '0'], ['1', '1', '0', '1', '0'], [
    '1', '1', '0', '0', '0'], ['0', '0', '0', '0', '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 0
    grid[i][j] = "0"
    dfs(grid,i+1,j)
    dfs(grid,i,j+1)
    dfs(grid,i-1,j)
    dfs(grid,i,j-1)
    return 1

def numIslands(grid):
    nums=0
    for i in range(len(grid)):
        for j in range(len(grid[0])):
            if grid[i][j] == "1":
                numIslands+=dfs(grid,i,j)
    return nums

print(numIslands([["1","1","1","1","0"],["1","1","0","1","0"],["1","1","0","0","0"],["0","0","0","0","0"]]))
