836. Rectangle Overlap

Description

Here

Intuition

1D

For example, we have 2 segemnts (x1, x2), (x3, x4):

# case 1
x1              x2
|               |
-----------------
          x3              x4
          |               |
          -----------------

# case 2
x1              x2
|               |
-----------------
          x3              x4
          |               |
          -----------------

x1 < x4 && x3 < x2

2D

For 2d,

  1. horizontal
    1. must satisfy x1 < x4 && x3 < x2
  2. Vertical
    1. must satisfy y1 < y4 && y3 < y2

Solution

Solution

results matching ""

    No results matching ""