-
Notifications
You must be signed in to change notification settings - Fork 112
/
0835-ImageOverlap.cs
36 lines (31 loc) · 1.05 KB
/
0835-ImageOverlap.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
//-----------------------------------------------------------------------------
// Runtime: 92ms
// Memory Usage: 25.3 MB
// Link: https://leetcode.com/submissions/detail/398960221/
//-----------------------------------------------------------------------------
using System;
namespace LeetCode
{
public class _0835_ImageOverlap
{
public int LargestOverlap(int[][] img1, int[][] img2)
{
int count = 0, N = img1.Length;
var counts = new int[N * 2, N * 2];
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
{
if (img1[i][j] == 0)
continue;
for (int m = 0; m < N; m++)
for (int n = 0; n < N; n++)
{
if (img2[m][n] == 0)
continue;
count = Math.Max(count, ++counts[N + i - m, N + j - n]);
}
}
return count;
}
}
}