Find the left down corner and right up corner of shared area .
public class Solution {
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int ac = (D-B)*(C-A);
int eg = (H-F)*(G-E);
int share1x = Math.max(A, E);
int share1y= Math.max(B, F);
int share2x = Math.min(C, G);
int share2y= Math.min(D, H);
return ac+eg-(share2y-share1y)*(share2x-share1x);
}
}
没有评论:
发表评论