Leetcode 963.Minimum Area Rectangle II

**Python:**
def minAreaFreeRect(self, points):
    points = [complex(*z) for z in sorted(points)]
    seen = collections.defaultdict(list)
    for P, Q in itertools.combinations(points, 2):
        seen[Q - P].append((P + Q) / 2)

    ans = float("inf")
    for A, candidates in seen.iteritems():
        for P, Q in itertools.combinations(candidates, 2):
            if A.real * (P - Q).real == -A.imag * (P - Q).imag:
                ans = min(ans, abs(A) * abs(P - Q))
    return ans if ans < float("inf") else 0

你可能感兴趣的:(Leetcode 963.Minimum Area Rectangle II)