My 4 line Python solution


  • 0
    W
    def computeArea(self, A, B, C, D, E, F, G, H):
        x1,x2,y1,y2=C-A,G-E,D-B,H-F;
        x=0 if max(abs(E-C),abs(G-A))>x1+x2 else min(x1,x2,abs(E-C),abs(G-A))
        y=0 if max(abs(D-F),abs(H-B))>y1+y2 else min(y1,y2,abs(D-F),abs(H-B))
        return x1*y1+x2*y2-x*y

Log in to reply
 

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