661. Image Smoother Easy
1/**
2 * [661] Image Smoother
3 *
4 * An image smoother is a filter of the size 3 x 3 that can be applied to each cell of an image by rounding down the average of the cell and the eight surrounding cells (i.e., the average of the nine cells in the blue smoother). If one or more of the surrounding cells of a cell is not present, we do not consider it in the average (i.e., the average of the four cells in the red smoother).
5 * <img alt="" src="https://assets.leetcode.com/uploads/2021/05/03/smoother-grid.jpg" style="width: 493px; height: 493px;" />
6 * Given an m x n integer matrix img representing the grayscale of an image, return the image after applying the smoother on each cell of it.
7 *
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2021/05/03/smooth-grid.jpg" style="width: 613px; height: 253px;" />
10 * Input: img = [[1,1,1],[1,0,1],[1,1,1]]
11 * Output: [[0,0,0],[0,0,0],[0,0,0]]
12 * Explanation:
13 * For the points (0,0), (0,2), (2,0), (2,2): floor(3/4) = floor(0.75) = 0
14 * For the points (0,1), (1,0), (1,2), (2,1): floor(5/6) = floor(0.83333333) = 0
15 * For the point (1,1): floor(8/9) = floor(0.88888889) = 0
16 *
17 * Example 2:
18 * <img alt="" src="https://assets.leetcode.com/uploads/2021/05/03/smooth2-grid.jpg" style="width: 613px; height: 253px;" />
19 * Input: img = [[100,200,100],[200,50,200],[100,200,100]]
20 * Output: [[137,141,137],[141,138,141],[137,141,137]]
21 * Explanation:
22 * For the points (0,0), (0,2), (2,0), (2,2): floor((100+200+200+50)/4) = floor(137.5) = 137
23 * For the points (0,1), (1,0), (1,2), (2,1): floor((200+200+50+200+100+100)/6) = floor(141.666667) = 141
24 * For the point (1,1): floor((50+200+200+200+200+100+100+100+100)/9) = floor(138.888889) = 138
25 *
26 *
27 * Constraints:
28 *
29 * m == img.length
30 * n == img[i].length
31 * 1 <= m, n <= 200
32 * 0 <= img[i][j] <= 255
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/image-smoother/
38// discuss: https://leetcode.com/problems/image-smoother/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn image_smoother(img: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
44 vec![]
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_661() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.