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)
}Discussion 0
Join free to post in the discussion.
Related questions
- What a 504 from Nginx meansBackend Developer
- Python default list surpriseBackend Developer
- Edges in a tree with n nodesBackend Developer
- Most nodes in a binary tree of height 3Backend Developer
- What inorder traversal of a BST givesBackend Developer
- Preorder output of a small treeBackend Developer
- Traversal for freeing a whole treeBackend Developer
- Data structure for level-order traversalBackend Developer