-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSolution.java
More file actions
34 lines (29 loc) · 896 Bytes
/
Solution.java
File metadata and controls
34 lines (29 loc) · 896 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
34
package _661;
class Solution {
public int[][] imageSmoother(int[][] M) {
int[][] result = new int[M.length][M[0].length];
int sum;
int count;
int xLen = M.length;
int yLen = M[0].length;
int nx, ny;
for (int x = 0; x < M.length; x++) {
for (int y = 0; y < M[x].length; y++) {
sum = 0;
count = 0;
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
nx = x+i;
ny = y+j;
if (nx >= 0 && nx < xLen && ny >= 0 && ny < yLen) {
sum += M[nx][ny];
count++;
}
}
}
result[x][y] = sum / count;
}
}
return result;
}
}