-
Notifications
You must be signed in to change notification settings - Fork 112
/
0661-ImageSmoother.cs
38 lines (36 loc) · 1.21 KB
/
0661-ImageSmoother.cs
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
35
36
37
38
//-----------------------------------------------------------------------------
// Runtime: 320ms
// Memory Usage: 34.9 MB
// Link: https://leetcode.com/submissions/detail/344234305/
//-----------------------------------------------------------------------------
namespace LeetCode
{
public class _0661_ImageSmoother
{
public int[][] ImageSmoother(int[][] M)
{
var rows = M.Length;
var cols = M[0].Length;
int[][] answer = new int[rows][];
for (var r = 0; r < rows; ++r)
{
answer[r] = new int[cols];
for (var c = 0; c < cols; ++c)
{
int count = 0;
for (var nr = r - 1; nr <= r + 1; nr++)
for (var nc = c - 1; nc <= c + 1; nc++)
{
if (0 <= nr && nr < rows && 0 <= nc && nc < cols)
{
answer[r][c] += M[nr][nc];
count++;
}
}
answer[r][c] /= count;
}
}
return answer;
}
}
}