zoukankan      html  css  js  c++  java
  • 836. 矩形重叠

    矩形以列表 [x1, y1, x2, y2] 的形式表示,其中 (x1, y1) 为左下角的坐标,(x2, y2) 是右上角的坐标。

    如果相交的面积为正,则称两矩形重叠。需要明确的是,只在角或边接触的两个矩形不构成重叠。

    给出两个矩形,判断它们是否重叠并返回结果。

    示例 1:

    输入:rec1 = [0,0,2,2], rec2 = [1,1,3,3]
    输出:true
    示例 2:

    输入:rec1 = [0,0,1,1], rec2 = [1,0,2,1]
    输出:false
     

    提示:

    两个矩形 rec1 和 rec2 都以含有四个整数的列表的形式给出。
    矩形中的所有坐标都处于 -10^9 和 10^9 之间。
    x 轴默认指向右,y 轴默认指向上。
    你可以仅考虑矩形是正放的情况。

    来源:力扣(LeetCode)
    链接:https://leetcode-cn.com/problems/rectangle-overlap

    class Solution:
        def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:
            if rec1[0]<=rec2[0]:
                x1,y1,x2,y2=rec1[0],rec1[1],rec1[2],rec1[3]
                x11,y11,x22,y22=rec2[0],rec2[1],rec2[2],rec2[3]
            else:
                x1,y1,x2,y2=rec2[0],rec2[1],rec2[2],rec2[3]
                x11,y11,x22,y22=rec1[0],rec1[1],rec1[2],rec1[3]
            if x11>=x2:return False
            else:
                if y11>=y2 or y22<=y1:return False 
            return True

    简化=>

    class Solution:
        def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:
            [x1, y1, x2, y2] = rec1
            [x11, y11, x22, y22] = rec2
            if x1 >= x22 or x2 <= x11 or y1 >= y22 or y2 <= y11:
                return False
            return True
  • 相关阅读:
    HTTP状态码
    firefox浏览器新建页面一直处于刷新状态解决方法
    firefox浏览器需要新建窗口时以新建标签页代替
    bash基础教程
    sqoop的导入|Hive|Hbase
    sqoop导出数据|Hive|HDFS和脚本编写
    sqoop安装
    sqoop简介和原理分析
    Oozie安装
    Oozie框架介绍
  • 原文地址:https://www.cnblogs.com/xxxsans/p/13777473.html
Copyright © 2011-2022 走看看