algorithm notes: leetcode#836 rectangle overlap

Problem


Solution


Initial thoughts

Python implementation

1
2
3
4
5
6
class :
def isRectangleOverlap(self, rec1, rec2):
return not (rec1[0] >= rec2[2] or
rec1[1] >= rec2[3] or
rec1[2] <= rec2[0] or
rec1[3] <= rec2[1])

Java implementation

1
2
3
4
5
6
7
8
class {
public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
return !(rec1[0] >= rec2[2] ||
rec1[1] >= rec2[3] ||
rec1[2] <= rec2[0] ||
rec1[3] <= rec2[1]);
}
}

Time complexity

O(1).

Space complexity

O(1).


836. Rectangle Overlap
(中文版) 算法笔记: 力扣#836 矩形重叠