661.Image Smoother

`示例 1:​输入:[[1,1,1], [1,0,1], [1,1,1]]输出:[[0, 0, 0], [0, 0, 0], [0, 0, 0]]解释:对于点 (0,0), (0,2), (2,0), (2,2): 平均(3/4) = 平均(0.75) = 0对于点 (0,1), (1,0), (1,2), (2,1): 平均(5/6) = 平均(0.83333333) = 0对于点 (1,1): 平均(8/9) = 平均(0.88888889) = 0注意:​给定矩阵中的整数范围为 [0, 255]。矩阵的长和宽的范围均为 [1, 150]。`

`class Solution {public:    vector<vector<int>> imageSmoother(vector<vector<int>>& M) {        int r=M.size();        int c=M[0].size();        if(r==1 && c==1) return M;        vector<vector<int>> res(M);        if(r==1)        {            res[0][0]=(M[0][0]+M[0][1])/2;            res[0][c-1]=(M[0][c-1]+M[0][c-2])/2;            for(int i=1;i<c-1;i++)            res[0][i] = (M[0][i] + M[0][i-1] +M[0][i+1] )/3;            return res;        }       if(c==1)        {            res[0][0]=(M[0][0]+M[1][0])/2;            res[r-1][0]=(M[r-1][0]+M[r-2][0])/2;            for(int i=1;i<r-1;i++)            res[i][0] = (M[i][0] + M[i-1][0] +M[i+1][0])/3;            return res;        }​        for(int i=1;i<r-1;i++)            for(int j=1;j<c-1;j++)                res[i][j] =(M[i][j] +M[i-1][j]+ M[i][j-1] + M[i-1][j-1]+ M[i][j+1] + M[i+1][j] + M[i+1][j+1] + M[i-1][j+1] + M[i+1][j-1])/9;        for(int i=1;i<c-1;i++)            res[0][i] = (M[0][i] + M[0][i-1] +M[0][i+1] +M[1][i] + M[1][i-1]+M[1][i+1])/6;        for(int i=1;i<c-1;i++)             res[r-1][i] = (M[r-1][i] + M[r-1][i-1] +M[r-1][i+1] +M[r-2][i] + M[r-2][i-1]+M[r-2][i+1])/6;        for(int i=1;i<r-1;i++)            res[i][0] = (M[i][0] + M[i-1][0] +M[i+1][0] +M[i][1] + M[i-1][1]+M[i+1][1])/6;​        for(int i=1;i<r-1;i++)                res[i][c-1] = (M[i][c-1] + M[i-1][c-1] +M[i+1][c-1] +M[i][c-2] + M[i-1][c-2]+M[i+1][c-2])/6;​        res[0][0]=(M[0][0]+M[0][1] +M[1][1]+M[1][0])/4;        res[0][c-1]=(M[0][c-1]+M[0][c-2]+M[1][c-1]+M[1][c-2])/4;        res[r-1][0]=(M[r-1][0]+M[r-1][1]+M[r-2][0]+M[r-2][1])/4;        res[r-1][c-1]=(M[r-1][c-1]+M[r-2][c-1]+M[r-2][c-2]+M[r-1][c-2])/4;        return res;    }​};`