Guest User

Untitled

a guest
May 22nd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. class Solution {
  2. public:
  3. int largestOverlap(vector<vector<int>>& A, vector<vector<int>>& B) {
  4. int n = A.size();
  5. vector<int> pointsA, pointsB;
  6. for (int i = 0; i < n; ++i)
  7. {
  8. for (int j = 0; j < n; ++j)
  9. {
  10. if (A[i][j])pointsA.push_back(i * n + j);
  11. if (B[i][j])pointsB.push_back(i * n + j);
  12. }
  13. }
  14. unordered_map<string, int> dist;
  15. int res = 0;
  16. for (const auto& pA : pointsA)
  17. {
  18. for (const auto& pB : pointsB)
  19. {
  20. int xA = pA / n, yA = pA % n, xB = pB / n, yB = pB % n;
  21. string key = to_string(xA - xB) + ":" + to_string(yA - yB);
  22. ++dist[key];
  23. res = max(res, dist[key]);
  24. }
  25. }
  26. return res;
  27. }
  28. };
Add Comment
Please, Sign In to add comment