【算法】Rectangles' Area

【算法】Rectangles' Area

1
2
3
4
5
6
7
8
9
10
11
12
int solution(int K, int L, int M, int N, int P, int Q, int R, int S) {
// write your code in C++11 (g++ 4.8.2)
int endx = std::max(M, R);
int startx = std::min(K, P);
int width = M - K + R - P - (endx-startx);
int endy = std::max(N,S);
int starty = std::min(L,Q);
int height = N - L + S - Q - ( endy - starty );
return (M - K) * (N - L) + (R - P) * (S - Q) - width * height;
}

Yunjie Zhang wechat
扫一扫上面的二维码加我微信