626. 矩形重叠

626. 矩形重叠

中文English

给定两个矩形,判断这两个矩形是否有重叠。

样例

样例 1:

输入 : l1 = [0, 8], r1 = [8, 0], l2 = [6, 6], r2 = [10, 0]
输出 : true

样例 2:

输入 : [0, 8], r1 = [8, 0], l2 = [9, 6], r2 = [10, 0]
输出 : false

注意事项

l1代表第一个矩形的左上角
r1代表第一个矩形的右下角
l2代表第二个矩形的左上角
r2代表第二个矩形的右下角

保证:l1 != r1 并且 l2 != r2

"""
Definition for a point.
class Point:
    def __init__(self, a=0, b=0):
        self.x = a
        self.y = b
"""

class Solution:
    """
    @param l1: top-left coordinate of first rectangle
    @param r1: bottom-right coordinate of first rectangle
    @param l2: top-left coordinate of second rectangle
    @param r2: bottom-right coordinate of second rectangle
    @return: true if they are overlap or false
    """
    def doOverlap(self, l1, r1, l2, r2):
        # write your code here
        #满足4个边界点均小于或者大于的时候,找到4个不重叠的情况
        if (r1.x < l2.x) or (l1.y < r2.y) or (r2.x < l1.x) or (l2.y < r1.y):
            return False 
        return True 

 

posted @ 2020-06-29 00:09  风不再来  阅读(83)  评论(0编辑  收藏  举报