Skip to content

836. Rectangle Overlap 👍

  • Time: $O(1)$
  • Space: $O(1)$
1
2
3
4
5
6
7
class Solution {
 public:
  bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) {
    return rec1[0] < rec2[2] && rec2[0] < rec1[2] &&  //
           rec1[1] < rec2[3] && rec2[1] < rec1[3];
  }
};
1
2
3
4
5
6
7
class Solution {
  public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
    return                                        //
        rec1[0] < rec2[2] && rec2[0] < rec1[2] && //
        rec1[1] < rec2[3] && rec2[1] < rec1[3];
  }
}
1
2
3
class Solution:
  def isRectangleOverlap(self, rec1: list[int], rec2: list[int]) -> bool:
    return rec1[0] < rec2[2] and rec2[0] < rec1[2] and rec1[1] < rec2[3] and rec2[1] < rec1[3]