java 661. Image Smoother.java

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 661. Image Smoother.java相关的知识,希望对你有一定的参考价值。

class Solution {
    public int[][] imageSmoother(int[][] M) {
        if (M == null || M.length < 1 || M[0].length < 1) return M;
        int m = M.length, n = M[0].length;
        int[][] res = new int[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                int temp = 0, cnt = 0;
                for (int k = Math.max(0, i - 1); k <= Math.min(i + 1, m - 1); k++) {
                    for (int l = Math.max(0, j - 1); l <= Math.min(j + 1, n - 1); l++) {
                        temp += M[k][l];
                        cnt++;
                    }
                }
                res[i][j] = temp / cnt;
            }
        }
        return res;
    }
}

以上是关于java 661. Image Smoother.java的主要内容,如果未能解决你的问题,请参考以下文章

661. Image Smoother

[leetcode-661-Image Smoother]

LeetCode 661. Image Smoother (图像平滑)

[LeetCode] 661. Image Smoother_Easy

leetcode 661. 图片平滑器(Image Smoother)

LeetCode Image Smoother