0835.cpp (655B)
1 class Solution { 2 public: 3 int largestOverlap(const vector<vector<int>> &img1, const vector<vector<int>> &img2) { 4 const int n = img1.size(); 5 vector<int> one, two; 6 unordered_map<int, int> count; 7 for (int i = 0; i < n; i++) { 8 for (int j = 0; j < n; j++) { 9 if (img1[i][j]) one.push_back(i * 100 + j); 10 if (img2[i][j]) two.push_back(i * 100 + j); 11 } 12 } 13 14 for (int i : one) 15 for (int j : two) 16 count[i - j]++; 17 18 int res = 0; 19 for (auto it : count) 20 res = max(res, it.second); 21 return res; 22 } 23 };