Minimum Area Rectangle II LeetCode solution in C++

1
#define x1 points[i][0]
2
#define y1 points[i][1]
3
#define x2 points[j][0]
4
#define y2 points[j][1]
5
#define x3 points[k][0]
6
#define y3 points[k][1]
7

8
class Solution {
9
public:
10
double minAreaFreeRect(vector<vector<int>> &points) {
11
int ans = INT_MAX;
12
sort(points.begin(), points.end());
13
set<pair<int, int>> st;
14
for (auto &p : points) st.insert({p[0], p[1]});
15

16
for (int i = 0; i != points.size() && ans != 1; i++)
17
for (int j = i + 1; j != points.size() && ans != 1; j++)
18
for (int k = j + 1; k != points.size() && ans != 1; k++)
19
if ((x1 - x2) * (x2 - x3) + (y1 - y2) * (y2 - y3) == 0 &&
20
st.count({x1 + x3 - x2, y1 + y3 - y2}))
21
ans = min(ans, abs((y1 - y2) * (x3 - x2) - (x1 - x2) * (y3 - y2)));
22

23
return ans == INT_MAX ? 0.0 : double(ans);
24
}
25
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0