美文网首页
223. Rectangle Area

223. Rectangle Area

作者: JERORO_ | 来源:发表于2018-07-18 22:13 被阅读0次

问题描述

思路

先算出总面积,再检查是否重合,是则减去重合部分

def computeArea(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
    """

    total = (C-A)*(D-B) + (G-E)*(H-F)
    if C<=E or G<=A: return total
    if H<=B or F>=D: return total
    arr1 = sorted([A, C, E, G])
    arr2 = sorted([B, D, F, H])
    wid = arr1[2] - arr1[1]
    hig = arr2[2] - arr2[1]
    return total - wid*hig

相关文章

网友评论

      本文标题:223. Rectangle Area

      本文链接:https://www.haomeiwen.com/subject/bknapftx.html