Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int minAreaRect(vector<vector<int>>& points) {
- unordered_map<int, unordered_set<int>> um;
- int res = INT_MAX;
- for (vector<int>& p: points) {
- um[p[0]].insert(p[1]);
- }
- for (int i = 0; i < points.size() - 1; i++) {
- for (int j = i + 1; j < points.size(); j++) {
- if (points[i][0] == points[j][0] || points[i][1] == points[j][1]) {
- continue;
- }
- if (um[points[i][0]].count(points[j][1]) && um[points[j][0]].count(points[i][1])) {
- int sizetmp = abs(points[i][0] - points[j][0]) * abs(points[i][1] - points[j][1]);
- res = min(sizetmp, res);
- }
- }
- }
- return res == INT_MAX ? 0 : res;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement