【leetcode❤python】 223. Rectangle Area

#-*- coding: UTF-8 -*-
#先判断是否有重叠
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 C<=E or B>=H or A>=G or D<=F:
            return (C-A)*(D-B)+(G-E)*(H-F)
        width=min(C,G)-max(E,A)
        height=min(D,H)-max(B,F)
        
        return (C-A)*(D-B)+(G-E)*(H-F)-width*height

原文地址:https://www.cnblogs.com/kwangeline/p/5999531.html