class Solution {
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
long long tot=0;
tot+=(C-A)*(D-B);
tot+=(G-E)*(H-F);
long long tip1=0;
long long tip2=0;
if (E<A){
if (G<=C && G>=A) tip1=G-A;
else if (G>C) tip1=C-A;
}
else if (E>=A && E<=C){
if (G<=C) tip1=G-E;
else if (G>C) tip1=C-E;
}
if (F<B){
if (H<=D && H>=B) tip2=H-B;
else if (H>D) tip2=D-B;
}
else if (F>=B && F<=D){
if (H<=D) tip2=H-F;
else if (H>D) tip2=D-F;
}
tot-=tip1*tip2;
return tot;
}
};
[LeetCode]223. 矩形面积
最新推荐文章于 2022-03-24 22:45:16 发布