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](https://leetcode.com/static/images/problemset/rectangle_area.png)
Assume that the total area is never beyond the maximum possible value of int.
给出对角线上两点坐标,求矩形面积。方法求出重合矩形的对角线两点坐标。
package leetcode;
public class RectangleArea {
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int area = (C-A)*(D-B) + (G - E) * (H - F);
int x1 = Math.max(A, E); int y1 = Math.max(B, F);
int x2 = Math.min(C, G); int y2 = Math.min(D, H);
if (x2 <= x1 || y2 <= y1){
return area;
}else {
int coincide = (x2-x1) * (y2-y1);
return area - coincide;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}