# LeetCode: 391. 完美矩形¶

## 1、题目描述¶

rectangles = [
[1,1,3,3],
[3,1,4,2],
[3,2,4,4],
[1,3,2,4],
[2,3,3,4]
]



rectangles = [
[1,1,2,3],
[1,3,2,4],
[3,1,4,2],
[3,2,4,4]
]



rectangles = [
[1,1,3,3],
[3,1,4,2],
[1,3,2,4],
[3,2,4,4]
]



rectangles = [
[1,1,3,3],
[3,1,4,2],
[1,3,2,4],
[2,2,4,4]
]



## 2、解题思路¶

class Solution:
def isRectangleCover(self, rectangles: List[List[int]]) -> bool:
area = 0
point_set = set()

for x, y, x1, y1 in rectangles:
area += (x1 - x) * (y1 - y)
point_set.add((x, y)) if (x, y) not in point_set else point_set.remove((x, y))
point_set.add((x1, y1)) if (x1, y1) not in point_set else point_set.remove((x1, y1))
point_set.add((x, y1)) if (x, y1) not in point_set else point_set.remove((x, y1))
point_set.add((x1, y)) if (x1, y) not in point_set else point_set.remove((x1, y))
if len(point_set) != 4:
return False

p1, p2, p3, p4 = sorted(point_set)
if p1[0] == p2[0] and p1[1] == p3[1] and p2[1] == p4[1] and p3[0] == p4[0]:
return (p4[1] - p1[1]) * (p4[0] - p1[0]) == area

return False