We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ee319fe commit 7323c1fCopy full SHA for 7323c1f
Python/minimum-area-rectangle-ii.py
@@ -0,0 +1,25 @@
1
+# Time: O(n^2 ~ n^3)
2
+# Space: O(n^2)
3
+
4
+import collections
5
+import itertools
6
7
8
+class Solution(object):
9
+ def minAreaFreeRect(self, points):
10
+ """
11
+ :type points: List[List[int]]
12
+ :rtype: float
13
14
+ points.sort()
15
+ points = [complex(*z) for z in points]
16
+ lookup = collections.defaultdict(list)
17
+ for P, Q in itertools.combinations(points, 2):
18
+ lookup[P-Q].append((P+Q) / 2)
19
20
+ result = float("inf")
21
+ for A, candidates in lookup.iteritems():
22
+ for P, Q in itertools.combinations(candidates, 2):
23
+ if A.real * (P-Q).real + A.imag * (P-Q).imag == 0.0:
24
+ result = min(result, abs(A) * abs(P-Q))
25
+ return result if result < float("inf") else 0.0
0 commit comments