Lintcode 626. Rectangle Overlap (Easy) (Python)

Rectangle Overlap

Description:

Given two rectangles, find if the given two rectangles overlap or not.

Example

Given l1 = [0, 8], r1 = [8, 0], l2 = [6, 6], r2 = [10, 0], return true

Given l1 = [0, 8], r1 = [8, 0], l2 = [9, 6], r2 = [10, 0], return `false

Code:

"""
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
        a = True if max(l1.x,l2.x)<=min(r1.x,r2.x) else False
        b = True if min(l1.y,l2.y)>=max(r1.y,r2.y) else False
        return a and b

猜你喜欢

转载自blog.csdn.net/weixin_41677877/article/details/81176853