forked from AnasImloul/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImage Overlap.cpp
More file actions
29 lines (28 loc) · 809 Bytes
/
Image Overlap.cpp
File metadata and controls
29 lines (28 loc) · 809 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
// Runtime: 428 ms (Top 30.81%) | Memory: 12.5 MB (Top 26.58%)
class Solution {
public:
int largestOverlap(vector<vector<int>>& img1, vector<vector<int>>& img2) {
int n=img1.size();
vector<pair<int,int>>vec_a;
vector<pair<int,int>>vec_b;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(img1[i][j]==1){
vec_a.push_back({i,j});
}
if(img2[i][j]==1){
vec_b.push_back({i,j});
}
}
}
int ans=0;
map<pair<int,int>,int>mp;
for(auto [i1,j1]:vec_a){
for(auto [i2,j2]:vec_b){
mp[{i1-i2,j1-j2}]++;
ans=max(ans,mp[{i1-i2,j1-j2}]);
}
}
return ans;
}
};