package leetcode;

/**
 * https://leetcode.com/problems/image-smoother/
 */
public class Problem661 {
    public int[][] imageSmoother(int[][] M) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem661 prob = new Problem661();
        // [[0, 0, 0],
        //  [0, 0, 0],
        //  [0, 0, 0]]
        System.out.println(prob.imageSmoother(new int[][]{
            {1, 1, 1},
            {1, 0, 1},
            {1, 1, 1}
        }));
    }
}

@@ -153,340 +153,1599 @@
     
-// TODO%0A        return null;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem661 prob = new Problem661();%0A        // %5B%5B0, 0, 0%5D,%0A        //  %5B0, 0, 0%5D,%0A        //  %5B0, 0, 0%5D%5D%0A        System.out.println(prob.imageSmoother(new int%5B%5D%5B%5D%7B%0A            %7B1, 1, 1%7D,%0A            %7B1, 0, 1%7D,%0A            %7B1, 1, 1%7D%0A        %7D))
+int maxRow = M.length;%0A        int maxCol = 0;%0A        if (maxRow %3E 0) %7B%0A            maxCol = M%5B0%5D.length;%0A        %7D%0A        int%5B%5D%5B%5D result = new int%5BmaxRow%5D%5BmaxCol%5D;%0A        for (int i = 0; i %3C M.length; i++) %7B%0A            for (int j = 0; j %3C M%5Bi%5D.length; j++) %7B%0A                result%5Bi%5D%5Bj%5D = calculate(M, maxRow, maxCol, i, j);%0A            %7D%0A        %7D%0A        return result;%0A    %7D%0A%0A    private static int calculate(int%5B%5D%5B%5D m, int maxRow, int maxCol, int row, int col) %7B%0A        int total = m%5Brow%5D%5Bcol%5D;%0A        int count = 1;%0A        // top%0A        if (row - 1 %3E= 0) %7B%0A            total += m%5Brow - 1%5D%5Bcol%5D;%0A            count++;%0A        %7D%0A        // top right%0A        if (row - 1 %3E= 0 && col + 1 %3C maxCol) %7B%0A            total += m%5Brow - 1%5D%5Bcol + 1%5D;%0A            count++;%0A        %7D%0A        // right%0A        if (col + 1 %3C maxCol) %7B%0A            total += m%5Brow%5D%5Bcol + 1%5D;%0A            count++;%0A        %7D%0A        // bottom right%0A        if (row + 1 %3C maxRow && col + 1 %3C maxCol) %7B%0A            total += m%5Brow + 1%5D%5Bcol + 1%5D;%0A            count++;%0A        %7D%0A        // bottom%0A        if (row + 1 %3C maxRow) %7B%0A            total += m%5Brow + 1%5D%5Bcol%5D;%0A            count++;%0A        %7D%0A        // bottom left%0A        if (row + 1 %3C maxRow && col - 1 %3E= 0) %7B%0A            total += m%5Brow + 1%5D%5Bcol - 1%5D;%0A            count++;%0A        %7D%0A        // left%0A        if (col - 1 %3E= 0) %7B%0A            total += m%5Brow%5D%5Bcol - 1%5D;%0A            count++;%0A        %7D%0A        // top left%0A        if (row - 1 %3E= 0 && col - 1 %3E= 0) %7B%0A            total += m%5Brow - 1%5D%5Bcol - 1%5D;%0A            count++;%0A        %7D%0A        return total / count
 ;%0A  

Solve problem 661