My two line solution by python

  • 0
    class Solution:
        # @param {integer} A
        # @param {integer} B
        # @param {integer} C
        # @param {integer} D
        # @param {integer} E
        # @param {integer} F
        # @param {integer} G
        # @param {integer} H
        # @return {integer}
        def computeArea(self, A, B, C, D, E, F, G, H):
            return self.computeRec(A,B,C,D) + self.computeRec(E,F,G,H) - self.computeRec(max(A,E), max(B,F), min(C,G), min(D,H))
        def computeRec(self, A, B, C, D):
            # compute area of a rectangle defined as above
            return (C-A)*(D-B) if A < C and B < D else 0

Log in to reply

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