Skip to content

Commit 108ac51

Browse files
committed
leetcode
1 parent 90eb0b0 commit 108ac51

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int largestOverlap(vector<vector<int>>& A, vector<vector<int>>& B) {
4+
vector<int> LA, LB;
5+
const int N = A.size();
6+
const int base = 2*N-1; // Note1
7+
unordered_map<int, int> count;
8+
for(int i = 0; i < N; i++)
9+
for(int j = 0; j < N; j++){
10+
if(A[i][j] == 1) LA.push_back(i*base+j);
11+
if(B[i][j] == 1) LB.push_back(i*base+j);
12+
}
13+
for (int i : LA) for (int j : LB) count[i - j]++;
14+
int res = 0;
15+
for (auto it : count) res = max(res, it.second);
16+
return res;
17+
}
18+
};

0 commit comments

Comments
 (0)