方法一:
class Solution:
def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:
return not(rec1[2] <= rec2[0] or
rec1[3] <= rec2[1] or
rec1[1] >= rec2[3] or
rec1[0] >= rec2[2])
方法二:
class Solution:
def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:
def intersect(p_left, p_right, q_left, q_right):
return min(p_right, q_right) > max(p_left, q_left)
return (intersect(rec1[0], rec1[2], rec2[0], rec2[2]) and
intersect(rec1[1], rec1[3], rec2[1], rec2[3]))