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
posted @ 2015-06-12 10:24  lilixu  阅读(109)  评论(0编辑  收藏  举报