class Solution:
def computeArea(self, A, B, C, D, E, F, G, H):
"""
:type A: int
:type B: int
:type C: int
:type D: int
:type E: int
:type F: int
:type G: int
:type H: int
:rtype: int
"""
#构建顺序 左→右→上→下
t1=(A,C,D,B)
t2=(E,G,H,F)
s1=(C-A)*(D-B)
s2=(G-E)*(H-F)
l1=min(C,G)-max(A,E)
l2=min(D,H)-max(B,F)
if l1>0 and l2>0:
return s1+s2-l1*l2
else:
return s1+s2
python leetcode 223. Rectangle Area
最新推荐文章于 2021-09-30 17:17:19 发布