My 16ms c solution treat x y respectively


  • 0
    D
    int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
           int x = 0; 
           int y = 0;
           if( A == C || B == D || E == G || F == H)
           {
               return ((C - A) * (D - B))?(A - C) * (B - D) : (G - E) * (H - F);
           }
           if(E >= C || G <= A || F >= D || H <= B )
           {
               return (A - C) * (B - D) + (G - E) * (H - F);
           }
           if(E <= A && G <= C)
           {
               x = G - A;
           }else if(E >= A && G >= C)
           {
               x = C - E;
           }else if(E >= A && G <= C)
           {
               x= G - E;
           }else if(E <= A && G >= C)
           {
               x = C - A;
           }
           if(F <= B && H <= D)
           {
               y = H - B;
           }else if(F >= B && H >= D)
           {
               y = D - F;
           }else if(F >= B && H <= D)
           {
               y = H - F;
           }else if(F <= B && H >= D)
           {
               y = D - B;
           }
           return ((A - C) * (B - D) + (G - E) * (H - F)) - x * y;
    
    
       }

Log in to reply
 

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