2
public int[][] colorBorder(int[][] grid, int row, int col, int color) {3
dfs(grid, row, col, grid[row][col]);4
for (int i = 0; i < grid.length; i++) {5
for (int j = 0; j < grid[0].length; j++) {15
int[][] dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};17
public void dfs(int[][] grid, int row, int col, int color) {18
grid[row][col] = -color;20
for (int i = 0; i < 4; i++) {21
int rowdash = row + dirs[i][0];22
int coldash = col + dirs[i][1];26
|| rowdash >= grid.length27
|| coldash >= grid[0].length28
|| Math.abs(grid[rowdash][coldash]) != color) {33
if (grid[rowdash][coldash] == color) {34
dfs(grid, rowdash, coldash, color);38
grid[row][col] = color;