structured Solution Java


  • 1
    A
    public class Solution {
         public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        
        int lowerBoundX = 0;
        int lowerBoundY = 0;
                
        int upperBoundX = 0;
        int upperBoundY = 0;
        
        if(A>G || B >H || C<E || D<F)
            return (D-B)*(C-A) + (H-F)*(G-E);
        
    
        
        lowerBoundX = ( A > E)? A:E;
        lowerBoundY = (B > F)? B: F;
        
        
        upperBoundX = (C> G)? G:C;
        upperBoundY = (D < H )? D : H;
        
        return (D-B)*(C-A) + (H-F)*(G-E) - (upperBoundY - lowerBoundY)*(upperBoundX - lowerBoundX);
        
        
        
    
        }
    }

Log in to reply
 

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