223. Rectangle Area

2018-07-18  本文已影响0人  JERORO_

问题描述

思路

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

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
上一篇 下一篇

猜你喜欢

热点阅读