-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperfect rectangle
41 lines (30 loc) · 1.16 KB
/
perfect rectangle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
link ;- https://leetcode.com/problems/perfect-rectangle/
class Solution:
def isRectangleCover(self, rectangle: List[List[int]]) -> bool:
a,b,c,d=rectangle[0]
area=0
seti=defaultdict(int)
for w,x,y,z in rectangle:
a=min(a,w)
b=min(b,x)
c=max(c,y)
d=max(d,z)
area+=(z-x)*(y-w)
area%=10**9+7
seti[(w,z)]+=1
seti[(w,x)]+=1
seti[(y,x)]+=1
seti[(y,z)]+=1
# print(seti)
if area!=((d-b)*(c-a))%(10**9+7) :
return False
for p,q in [[a,b],[a,d],[c,b],[c,d]]:
if (p,q) not in seti or seti[(p,q)]!=1:
return False
seti[(p,q)]=0
for i in seti:
if seti[i]%2!=0:
return False
return True
Given an array rectangles where rectangles[i] = [xi, yi, ai, bi] represents an axis-aligned rectangle. The bottom-left point of the rectangle is (xi, yi) and the top-right point of it is (ai, bi).
Return true if all the rectangles together form an exact cover of a rectangular region.