my 3 lines solution in python


  • 0
    Y

    class Solution(object):

    def computeArea(self, A, B, C, D, E, F, G, H):
        w = min(max(G - A, 0), G - E, C - A, max(C - E, 0))  # width of overlap part
        h = min(max(H - B, 0), H - F, D - B, max(D - F, 0))  # height of overlap part
        return (C - A) * (D - B) + (G - E) * (H - F) - w * h  # area1 + area2 - overlap area

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.