223. Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2Dplane.
Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.


223. Rectangle Area_第1张图片

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

求两个矩形的总面积, 关键点在于求矩形是否相交, 以及交集的面积。

判断是否相交: 1的左x点和2的右x点, 1 的右x点和2的左x点, 1的下y点和2的上y点, 1的上y点和2的下y点比较。


223. Rectangle Area_第2张图片

你可能感兴趣的:(223. Rectangle Area)