🚀

End of Year Sale: Use Coupon Code END2025 to Get Extra 25% Off.

02DAYS
:
00HOURS
:
34MINUTES
:
41SECONDS

Leetcode Problem 661. Image Smoother

661. Image Smoother

Leetcode Solutions

Approach: Create a New Smoothened Image

  1. Store the dimensions of the image in variables m and n.
  2. Create a new matrix smooth_img with dimensions m x n and initialize all cells to 0.
  3. Iterate over each cell in the original image img[i][j].
    • Initialize sum and count to 0.
    • Iterate over all possible neighbors (x, y) around img[i][j].
    • If (x, y) is a valid neighbor, add img[x][y] to sum and increment count.
    • Compute the average as sum / count and store the floored value in smooth_img[i][j].
  4. Return smooth_img.
UML Thumbnail

Approach: Space-Optimized Smoothened Image

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...