forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0963.py
20 lines (18 loc) · 740 Bytes
/
0963.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import itertools, collections
class Solution:
def minAreaFreeRect(self, points):
"""
:type points: List[List[int]]
:rtype: float
"""
points = [complex(*point) for point in sorted(points)]
mem = collections.defaultdict(list)
for p, q in itertools.combinations(points, 2):
mem[q - p].append((p + q) / 2)
res = float('inf')
for v1, mid_points in mem.items():
for a, b in itertools.combinations(mid_points, 2):
v2 = a - b
if abs(v1.real * v2.real + v1.imag * v2.imag) < 1e-5:
res = min(res, abs(v1) * abs(v2))
return res if res != float('inf') else 0