---
# System prepended metadata

title: 0223. Rectangle Area
tags: [Leetcode, Medium, Math]

---

# 0223. Rectangle Area
###### tags: `Leetcode` `Medium` `Math`
## 思路
先算出两个rectangle的面积
然后减去重叠部分面积即可
## Code
```python=
class Solution:
    def computeArea(self, ax1: int, ay1: int, ax2: int, ay2: int, bx1: int, by1: int, bx2: int, by2: int) -> int:
        area = (ax2-ax1)*(ay2-ay1)+(bx2-bx1)*(by2-by1)
        
        def getOverlapping(a1, b1, a2, b2):
            return max(a1, a2), min(b1, b2)
        
        x1, x2 = getOverlapping(ax1, ax2, bx1, bx2)
        y1, y2 = getOverlapping(ay1, ay2, by1, by2)
        if x1<x2 and y1<y2: return area-(x2-x1)*(y2-y1)
        else: return area
```