Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. class Solution {
  2. public:
  3.  
  4. int minAreaRect(vector<vector<int>>& points) {
  5. unordered_map<int, unordered_set<int>> um;
  6. int res = INT_MAX;
  7. for (vector<int>& p: points) {
  8. um[p[0]].insert(p[1]);
  9. }
  10. for (int i = 0; i < points.size() - 1; i++) {
  11. for (int j = i + 1; j < points.size(); j++) {
  12. if (points[i][0] == points[j][0] || points[i][1] == points[j][1]) {
  13. continue;
  14. }
  15. if (um[points[i][0]].count(points[j][1]) && um[points[j][0]].count(points[i][1])) {
  16. int sizetmp = abs(points[i][0] - points[j][0]) * abs(points[i][1] - points[j][1]);
  17. res = min(sizetmp, res);
  18. }
  19. }
  20. }
  21. return res == INT_MAX ? 0 : res;
  22. }
  23. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement