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
        """
        if min(C,G) > max(A,E):
            ow = min(C,G) - max(A,E)
        else:
            ow = 0
        if min(D,H) > max(B,F):
            oh = min(D,H) - max(B,F)
        else:
            oh = 0
        area = (C-A) * (D-B) + (G-E) * (H-F) - ow * oh
        return area
        

你可能感兴趣的:(223. Rectangle Area)