-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path661.cpp
More file actions
20 lines (20 loc) · 687 Bytes
/
661.cpp
File metadata and controls
20 lines (20 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
public:
vector<vector<int>> imageSmoother(vector<vector<int>>& M) {
int R = M.size(), C = M[0].size();
vector<vector<int>> ans(R,vector<int>(C));
for (int r = 0; r < R; ++r)
for (int c = 0; c < C; ++c) {
int count = 0;
for (int nr = r-1; nr <= r+1; ++nr)
for (int nc = c-1; nc <= c+1; ++nc) {
if (0 <= nr && nr < R && 0 <= nc && nc < C) {
ans[r][c] += M[nr][nc];
count++;
}
}
ans[r][c] /= count;
}
return ans;
}
};