bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 733. Flood Fill

733. Flood Fill

Leetcode Solutions

Depth-First Search for Flood Fill

  1. Store the original color of the starting pixel (sr, sc).
  2. Define a recursive function dfs that takes the current coordinates of the pixel.
  3. In the dfs function, check if the current pixel is out of bounds or not the original color; if so, return.
  4. Change the color of the current pixel to the new color.
  5. Recursively call dfs for the 4-directionally adjacent pixels (up, down, left, right).
  6. Invoke the dfs function starting from (sr, sc).
  7. Return the modified image.
UML Thumbnail

Breadth-First Search for Flood Fill

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...
bugfree Icon
OR