[LeetCode] 223. Rectangle Area

class Solution:
    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 = (D - B) * (C - A)
        area2 = (H - F) * (G - E)

        if E >= D or G <= A:
            area = 0
        if H <= B or F >= D:
            area = 0
        ycor = min(H, D) - max(F, B) if min(H, D) > max(F, B) else 0
        xcor = min(C, G) - max(A, E) if min(C, G) > max(A, E) else 0
        area = xcor * ycor
        return area1 + area2 - area

阅读更多
个人分类: LeetCode
上一篇LeetCode 42. Trapping Rain Water (python)
下一篇315. 计算右侧小于当前元素的个数 python
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭