美文网首页Leetcode
Leetcode 939. Minimum Area Recta

Leetcode 939. Minimum Area Recta

作者: SnailTyan | 来源:发表于2021-02-23 11:50 被阅读0次

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Minimum Area Rectangle

2. Solution

  • Version 1
class Solution:
    def minAreaRect(self, points):
        result = 0
        stat = set(map(tuple, points))

        for x1, y1 in points:
            for x2, y2 in points:
                if x1 == x2 or y1 == y2:
                    continue
                if (x1, y2) in stat and (x2, y1) in stat:
                    area = abs(x2 - x1) * abs(y2 - y1)
                    if area < result or result == 0:
                        result = area
        return result

Reference

  1. https://leetcode.com/problems/minimum-area-rectangle/

相关文章

网友评论

    本文标题:Leetcode 939. Minimum Area Recta

    本文链接:https://www.haomeiwen.com/subject/ndkhfltx.html