Line Sweep (Java) - ShuweiLeung/Thinking GitHub Wiki
1.(850:Hard)(非常经典题)Rectangle Area II
- The idea here is to maintain a list of non-overlapping rectangles to calculate final area. If a new rectangle does not overlap with any of the existing rectanlges, add it to the list. If there is an overlap, split the non-overlapping regions of the rectangle into smaller rectangles and compare with the rest of the list.
- For example, when a new rectangle (green) is compared with the current rectangle (blue), the non-overlapping regions can be split into two smaller rectangles. Rectangle 1 will be covered by the first overlapping case in addRectangle() and rectangle 2 will be covered by the third case. Rectangle 3 overlaps with the current rectangle and need not be considered.
- 根据下图的case1、case2、case3、case4进行矩形的分割,递归分割