代码
class Solution { public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int commonArea=0; if(!(E>=C||H<=B||D<=F||G<=A))//判断是否会重叠 { int s1=Math.max(A,E); int s2=Math.min(C,G); int s3=Math.max(B,F); int s4=Math.min(D,H); commonArea=(s2-s1)*(s4-s3); } int area1=(C-A)*(D-B); int area2=(G-E)*(H-F); int res=area1-commonArea+area2; return res; } }