class Solution {
boolean flag = false;
public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
int area1 = (ax2-ax1)*(ay2-ay1);
int area2 = (bx2-bx1)*(by2-by1);
int[] weight = both(ax1,ax2,bx1,bx2);
int[] lo = both(ay1,ay2,by1,by2);
if(flag)return area1+area2;
int bothweight = weight[1]-weight[0];
int bothlo = lo[1]-lo[0];
int botharea = bothlo*bothweight;
return area1+area2-botharea;
}
public int[] both(int x11,int x12,int x21,int x22){
int[] res = new int[2];
if(x12<=x21||x22<x11){
flag = true;
return res;
}
else {
res[0] = Math.max(x11,x21);
res[1] = Math.min(x12,x22);
}
return res;
}
}
九月份打卡全部完成!
纪念一下