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

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...