欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 美食 > Python | Leetcode Python题解之第391题完美矩形

Python | Leetcode Python题解之第391题完美矩形

2024/10/25 10:21:30 来源:https://blog.csdn.net/Mopes__/article/details/141835353  浏览:    关键词:Python | Leetcode Python题解之第391题完美矩形

题目:

题解:

class Solution:def isRectangleCover(self, rectangles: List[List[int]]) -> bool:area, minX, minY, maxX, maxY = 0, rectangles[0][0], rectangles[0][1], rectangles[0][2], rectangles[0][3]cnt = defaultdict(int)for rect in rectangles:x, y, a, b = rect[0], rect[1], rect[2], rect[3]area += (a - x) * (b - y)minX = min(minX, x)minY = min(minY, y)maxX = max(maxX, a)maxY = max(maxY, b)cnt[(x, y)] += 1cnt[(x, b)] += 1cnt[(a, y)] += 1cnt[(a, b)] += 1if area != (maxX - minX) * (maxY - minY) or cnt[(minX, minY)] != 1 or cnt[(minX, maxY)] != 1 or cnt[(maxX, minY)] != 1 or cnt[(maxX, maxY)] != 1:return Falsedel cnt[(minX, minY)], cnt[(minX, maxY)], cnt[(maxX, minY)], cnt[(maxX, maxY)]return all(c == 2 or c == 4 for c in cnt.values())

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com