Leetcode 223 Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane.

Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.

Rectangle Area

Assume that the total area is never beyond the maximum possible value of int.

两矩形面积相加后减去重叠部分

def compute_area(a, b, c, d, e, f, g, h)

    (c-a) * (d-b) + (g-e) * (h-f) - [([c,g].min-[a,e].max),0].max * [([d,h].min-[b,f].max),0].max

end

你可能感兴趣的:(LeetCode)