My 48ms python code

  • 1
    class Solution:
        def computeArea(self, A, B, C, D, E, F, G, H):
    		if G <= A or C <= E or D <= F or H <= B:
    			return (C-A)*(D-B) + (G-E)*(H-F)
    		if A <= E and B <= F and C >= G and D >= H:
    			return (C-A)*(D-B)
    		xx = sorted([A,C,E,G])
    		yy = sorted([B,D,F,H])
    		width = xx[2]-xx[1]
    		height = yy[2]-yy[1]
    		area = (C-A)*(D-B) + (G-E)*(H-F) - width*height
    		return area

Log in to reply

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