Skip to content
RED SAG Skills
medium10 pts · first answer countsgraphsdfsdebugging

Flood fill with the same colour

This flood fill marks cells by recolouring them instead of using a visited set. What happens if newColor equals the starting colour?

function fill(img, r, c, newColor) {
  const old = img[r][c]
  const go = (r, c) => {
    if (r < 0 || c < 0 || r >= img.length || c >= img[0].length) return
    if (img[r][c] !== old) return
    img[r][c] = newColor
    go(r + 1, c); go(r - 1, c); go(r, c + 1); go(r, c - 1)
  }
  go(r, c)
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions