LeetCode题解(0939):最小面积矩形(Python)
发布日期:2021-06-29 20:09:35 浏览次数:3 分类:技术文章

本文共 654 字,大约阅读时间需要 2 分钟。

题目:(中等)

标签:哈希表、几何

解法 时间复杂度 空间复杂度 执行用时
Ans 1 (Python) O ( N 2 ) O(N^2) O(N2) O ( N ) O(N) O(N) 764ms (87.97%)
Ans 2 (Python)
Ans 3 (Python)

解法一:

class Solution:    def minAreaRect(self, points: List[List[int]]) -> int:        ans = float("inf")        count_x = collections.defaultdict(set)        count_y = collections.defaultdict(set)        for x1, y1 in points:            for y2 in count_x[x1]:                for x2 in count_y[y1]:                    if x2 in count_y[y2]:                        ans = min(ans, abs(y2 - y1) * abs(x2 - x1))            count_x[x1].add(y1)            count_y[y1].add(x1)        return ans if ans != float("inf") else 0

转载地址:https://dataartist.blog.csdn.net/article/details/109839377 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:LeetCode题解(0954):二倍数对数组(Python)
下一篇:LeetCode题解(0930):和相同的二元子数组(Python)

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月22日 18时03分00秒