You are viewing a single comment's thread. Return to all comments →
Here is the python equivalent:
def getBiggestRegion(grid): maxRegion = 0 for i in range(len(grid)): for j in range(len(grid[0])): maxRegion = max(maxRegion, countCells(grid, i, j)) return maxRegion def countCells(grid, i, j): if (not(i in range(len(grid)) and j in range(len(grid[0])))): return 0 if (grid[i][j] == 0): return 0 count = 1 grid[i][j] = 0 count += countCells(grid, i + 1, j) count += countCells(grid, i - 1, j) count += countCells(grid, i, j + 1) count += countCells(grid, i, j - 1) count += countCells(grid, i + 1, j + 1) count += countCells(grid, i - 1, j - 1) count += countCells(grid, i - 1, j + 1) count += countCells(grid, i + 1, j - 1) return count
Seems like cookies are disabled on this browser, please enable them to open this website
DFS: Connected Cell in a Grid
You are viewing a single comment's thread. Return to all comments →
Here is the python equivalent: