-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageOverlap.cpp
More file actions
31 lines (30 loc) · 832 Bytes
/
ImageOverlap.cpp
File metadata and controls
31 lines (30 loc) · 832 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
class Solution {
public:
int largestOverlap(vector<vector<int>>& A, vector<vector<int>>& B) {
if (A.empty() || A[0].empty())
{
return 0;
}
int n = A.size();
int res = 0;
for (int i = 1 - n; i <= n -1; i++)
{
for (int j = 1-n; j <= n-1; j++)
{
int cur = 0;
for (int k = max(i, 0); k < min(i + n, n); k++)
{
for (int l = max(j, 0); l < min(j + n, n); l++)
{
if (A[k -i][l - j] == 1 && B[k][l] == 1)
{
cur ++;
}
}
}
res = max(res, cur);
}
}
return res;
}
};