836. Rectangle Overlap

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution {
public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
int[] rec1PointA = new int[]{rec1[0], rec1[1]};
int[] rec1PointB = new int[]{rec1[2], rec1[3]};
int[] rec2PointA = new int[]{rec2[0], rec2[1]};
int[] rec2PointB = new int[]{rec2[2], rec2[3]};

if (rec2PointA[0] >= rec1PointB[0] || rec2PointA[1] >= rec1PointB[1]) {
return false;
}

if (rec1PointA[0] >= rec2PointB[0] || rec1PointA[1] >= rec2PointB[1]) {
return false;
}

return true;
}
}

References

836. Rectangle Overlap