One kind of python solution

  • 0

    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
        area1 = (C - A)*(D - B)
        area2 = (G - E)*(H - F)
        #no interaction
        if H <= B or F >= D or C <= E or G <= A:
            commonArea = 0
            width = min(abs(H-B), H-F, D-B, abs(D-F))
            height = min(C-A, G-E, abs(C-E), abs(G-A))
            commonArea = width*height
        return area1 + area2 - commonArea

Log in to reply

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