# Question

Formatted question description: https://leetcode.ca/all/223.html

# 223. Rectangle Area

Medium

## Description

Find the total area covered by two rectilinear rectangles in a 2D plane.

Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.

Example:

Input: A = -3, B = 0, C = 3, D = 4, E = 0, F = -1, G = 9, H = 2

Output: 45

Note:

Assume that the total area is never beyond the maximum possible value of int.

# Algorithm

First find out all the cases of disjoint, there are only four types, one rectangle does not overlap at the top, bottom, left, and right positions of the other. In these four cases, the sum of the area of the two rectangles is returned.

In all other cases, two rectangles have an intersection. At this time, just calculate the length and width to find the size of the intersection area, and then subtract the intersection area from the sum of the two rectangular areas, to get the final answer.

Java