223. Rectangle Area
Last updated
Last updated
Input: A = -3, B = 0, C = 3, D = 4, E = 0, F = -1, G = 9, H = 2
Output: 45
Note:
Assume that the total area is never beyond the maximum possible value of int.class Solution {
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
long long all = (long long)(C-A)*(D-B)+(long long)(G-E)*(H-F);
int I = max(A,E);
int J = max(B,F);
int K = min(C,G);
int L = min(D,H);
long long cover = 0;
if(K<=I||L<=J)
cover = 0;
else
cover = (long long)(K-I)*(L-J);
return all-cover;
}
};