C++ solution lol


  • 0
    R

    A simple way to calculate the coordinates of the bottom-left point and top-right point of the overlapped area.

    class Solution {
    public:
        int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        	int I, J, K, L;
        	I = 0; J = 0; K = 0; L = 0;
        	if ((B <= F) && (F <= D))
        		J = F;
        	if ((F <= B) && (B <= H))
        		J = B;
        	if ((F <= D) && (D <= H))
        		L = D;
        	if ((B <= H) && (H <= D))
        		L = H;
        	if ((A <= E) && (E <= C))
        		I = E;
        	if ((E <= A) && (A <= G))
        		I = A;
        	if ((E <= C) && (C <= G))
        		K = C;
        	if ((A <= G) && (G <= C))
        		K = G;
        	return ((C - A)*(D - B) - (K - I)*(L - J) + (G - E)*(H - F));
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.