
223. Rectangle Area
class Solution(object):
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
"""
area = (D-B)*(C-A) + (H-F)*(G-E)
L1 = [A, C, E, G]
L2 = [B, D, F, H]
L1.sort()
L2.sort()
if (L1[0]==A and L1[1]==C) or (L1[0]==E and L1[1]==G):
return area
elif (L2[0]==B and L2[1]==D) or (L2[0]==F and L2[1]==H):
return area
else:
return area - (L1[2]-L1[1]) * (L2[2]-L2[1])