Skip to content

Commit 5d650eb

Browse files
authored
Create 661) imageSmoother.cpp
1 parent ef24936 commit 5d650eb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

661) imageSmoother.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
vector<vector<int>> imageSmoother(vector<vector<int>>& img) {
4+
int row=img.size();
5+
int col=img[0].size(); vector<vector<int>>result(row,vector<int>(col,0));
6+
for (int i=0;i<row;++i) {
7+
for(int j=0;j<col;++j) {
8+
int sum=0;
9+
int count=0;
10+
for(int x=max(0,i-1);x<=min(row-1,i+1);++x) {
11+
for(int y=max(0,j-1);y<=min(col-1,j+1);++y) {
12+
sum+=img[x][y];
13+
count++;
14+
}
15+
}
16+
result[i][j]=sum/count;
17+
}
18+
}
19+
return result;
20+
}
21+
22+
};

0 commit comments

Comments
 (0)