-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay19.cpp
More file actions
33 lines (31 loc) · 889 Bytes
/
Day19.cpp
File metadata and controls
33 lines (31 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution {
public:
int solve(vector<vector<int>>& img, int x, int y){
int m = img.size();
int n = img[0].size();
int sum = 0;
int count = 0;
for(int i=-1;i<=1;++i){
for(int j=-1;j<=1;++j){
int nx = x+i;
int ny = y+j;
if(nx >= 0 && nx < m && ny >= 0 && ny < n){
sum += img[nx][ny];
++count;
}
}
}
return sum/count;
}
vector<vector<int>> imageSmoother(vector<vector<int>>& img) {
int m = img.size();
int n = img[0].size();
vector<vector<int>> ans(m, vector<int>(n,0));
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
ans[i][j] = solve(img, i, j);
}
}
return ans;
}
};