Rectangle-Area
第86天。
今天的题目是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.
Assume that the total area is never beyond the maximum possible value of int.
一开始以为是求两个矩形重合部分的面积,后来仔细看了一下才发现是求它们的覆盖面积,好在把重合部分面积求出来后,求他们覆盖面积也比较简单,只需要先求出两个矩形的面积和之后再减去重合部分的面积就可以得到覆盖面积了。
1 | int area(int A,int B,int C,int D) { |
然后是dicuss
中比较简洁的解法:
1 | int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { |