Моє 1 створення

function bucketFill(grid, row, col, newColor) {
const oldColor = grid[row][col];
if (oldColor === newColor) return grid;

const newGrid = grid.map(r => […r]); // Створення глибокої копії

function fill(r, c) {
if (r < 0 || r >= newGrid.length || c < 0 || c >= newGrid[0].length || newGrid[r][c] !== oldColor) {
return;
}
newGrid[r][c] = newColor;
fill(r + 1, c);
fill(r - 1, c);
fill(r, c + 1);
fill(r, c - 1);
}

fill(row, col);
return newGrid;
}

Welcome to the forum @Liod642,

In the future, if you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Help button located on the challenge.

The Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

Happy coding

Please provide a link to the challenge and tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.