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.

在坐标中,求两个长方形的总面积

223. Rectangle Area_第1张图片

代码:


223. Rectangle Area_第2张图片
参考代码

解题思路:分别求两个长方形的面积,然后看两个长方形是否相交,如果不相交,直接返回面积和;如果相交,求出相交面积。

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