836. rectangles overlap check leetcode

836. rectangles overlap

A list rectangle [x1, y1, x2, y2] expressed in the form, where (x1, y1) coordinates of the lower left corner, (x2, y2) are the coordinates of the upper right corner.

If the intersecting area is positive, called two rectangles overlap. To be clear, the two rectangular sides or only at the corners of the contact does not constitute overlap.

Given two rectangles, it determines whether they overlap and returns the result.

Example 1:

Input: rec1 = [0,0,2,2], rec2 = [1,1,3,3]
Output: true
Example 2:

Input: rec1 = [0,0,1,1], rec2 = [1,0,2,1]
Output: false
Note:
two rectangular rec1 rec2 and are given in the form of a list containing four integers.
All coordinates in the rectangle are between 9 and 10 ^ -10 ^ 9.
default x-axis points to the right, y-axis pointing to the default.
You can consider only rectangular case is being put.
Source: leetcode
link: https://leetcode-cn.com/problems/rectangle-overlap/

Idea: Suppose

RECl: [0,0,2,2] -> X10, Y11, X12, Y13
REC2: [1,1,3,3] -> [on the x20, Y21, X22, Y23]
include mismatch:
X axis: x22 <= x10 or X12 <= on the x20
Y axis: y11 <= y23 or y21 <= y13
Code

class Solution:
    def isRectangleOverlap(self, rec1, rec2) -> bool:
        if rec1[1]>=rec2[3] or(rec1[0]>=rec2[2] or rec2[0]>=rec1[2]):
            return False
        elif rec2[1]>=rec1[3] or (rec1[0]>=rec2[2] or rec2[0]>=rec1[2]):
            return False
        else:
            return  True
a=Solution()
rec1 = [0,0,2,2]
rec2 = [1,1,3,3]
print(a.isRectangleOverlap(rec1,rec2))

Guess you like

Origin www.cnblogs.com/rmxob/p/12516736.html