Rectangle Area || LeetCode
把交叉点的坐标求出来即可。
#define max(a,b) ( (a)>(b)?(a):(b) ) #define min(a,b) ( (a)<(b)?(a):(b) ) int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int downx,downy,upx,upy; int crossArea; int all; downx=max(A,E); downy=max(B,F); upx =min(C,G); upy =min(D,H); if(downx>upx||downy>upy)crossArea=0; else crossArea=(upx-downx)*(upy-downy); all=(C-A)*(D-B)+(G-E)*(H-F); return all-crossArea; }