本文共 509 字,大约阅读时间需要 1 分钟。
class Solution { public: vector> imageSmoother(vector >& M) { int m = M.size(), n = M.front().size(); vector > result(m, vector (n)); for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) { int num = 0, sum = 0; for (int _i = max(0, i-1); _i <= min(m-1, i+1); ++_i) { for (int _j = max(0, j-1); _j <= min(n-1, j+1); ++_j) { sum += M[_i][_j]; ++num; } } result[i][j] = sum / num; } } return result; }};
转载地址:http://bbmki.baihongyu.com/