AC Python Solution


  • 1
    T
    class Solution:
    def computeArea(self, a, b, c, d, e, f, g, h):
        width = self._compute(a, c, e, g)
        height = self._compute(b, d, f, h)
        return (c - a) * (d - b) + (g - e) * (h - f) - width * height
    
    def _compute(self, a, b, c, d):
        if a > c:
            a, b, c, d = c, d, a, b
        if c < b < d:
            return b - c
        if d <= b:
            return d - c
        return 0

Log in to reply
 

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