A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bottom-left corner, and (x2, y2) are the coordinates of its top-right corner.

Two rectangles overlap if the area of their intersection is positive.  To be clear, two rectangles that only touch at the corner or edges do not overlap.

Given two (axis-aligned) rectangles, return whether they overlap.

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

Notes:

  1. Both rectangles rec1 and rec2 are lists of 4 integers.
  2. All coordinates in rectangles will be between -10^9 and 10^9.
class Solution(object):
def isRectangleOverlap(self, rec1, rec2):
"""
:type rec1: List[int]
:type rec2: List[int]
:rtype: bool
"""
if rec1[0]<=rec2[0]:
if rec2[0]>=rec1[2] or rec2[1]>=rec1[3] or rec2[3]<=rec1[1]:
return False
return True
else:
if rec2[2]<=rec1[0] or rec2[3]<=rec1[1] or rec2[1]>=rec1[3]:
return False
return True

  

[LeetCode&Python] Problem 836. Rectangle Overlap的更多相关文章

  1. 【Leetcode_easy】836. Rectangle Overlap

    problem 836. Rectangle Overlap solution: class Solution { public: bool isRectangleOverlap(vector< ...

  2. 836. Rectangle Overlap ——weekly contest 85

    Rectangle Overlap A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coor ...

  3. 【LeetCode】836. Rectangle Overlap 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/rectangle ...

  4. #Leetcode# 836. Rectangle Overlap

    https://leetcode.com/problems/rectangle-overlap/ A rectangle is represented as a list [x1, y1, x2, y ...

  5. [LeetCode&Python] Problem 492. Construct the Rectangle

    For a web developer, it is very important to know how to design a web page's size. So, given a speci ...

  6. 836. Rectangle Overlap 矩形重叠

    [抄题]: A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of i ...

  7. [LeetCode&Python] Problem 108. Convert Sorted Array to Binary Search Tree

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Fo ...

  8. [LeetCode&Python] Problem 387. First Unique Character in a String

    Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...

  9. [LeetCode&Python] Problem 427. Construct Quad Tree

    We want to use quad trees to store an N x N boolean grid. Each cell in the grid can only be true or ...

随机推荐

  1. 《高性能SQL调优精要与案例解析》一书谈SQL调优(SQL TUNING或SQL优化)学习

    <高性能SQL调优精要与案例解析>一书上市发售以来,很多热心读者就该书内容及一些具体问题提出了疑问,因读者众多外加本人日常工作的繁忙 ,在这里就SQL调优学习进行讨论并对热点问题统一作答. ...

  2. XAMPP/PHPnow/phpStudy安装使用对比

    一.XAMPP 1.1 下载 下载地址:https://www.apachefriends.org/download.html 1.2 安装 双击下载的安装程序进行安装,界面如下图,都是典型的下一步下 ...

  3. Cmd管理员运行

    Cmd管理员运行     C:\Windows\System32  

  4. Pl/sql 如何将oracle的表数据导出成excel文件?

    oracle将表数据导出成excel文件的方法 1)在SQL窗体上,查询需要导出的数据 --查询数据条件-- ; 结果视图 2)在查询结果的空白处,右键选择Copy to Excel 3) 查看导出e ...

  5. ubuntu 双硬盘挂载 windows分区自动挂载

    sudo fdisk -l 查看硬盘情况 1:新建一个目录,例:old 2:mount  /dev/sdb1  old 3:cd old 4:ls  (就可以看到新硬盘的内容了) 取消挂载:umoun ...

  6. Win10系列:VC++ XML文件解析

    XML文件按照元素标记来存储数据,通过遍历这些元素标记可以得到XML文件中所保存的数据.在C++/CX的类库中并未定义用于解析XML文件的类,但C++提供了能解析XML文件的框架和类库,如msxml4 ...

  7. java 一些容易忽视的小点-控制语句

    随机数 .Math.random()该方法用于产生一个0到1区间的double类型的随机数,但是不包括1 if-else循环语句 如果if语句不写{},则只能作用于后面的第一条语句 switch语句 ...

  8. 利用VisualVm和JMX远程监控Java进程

    自Java 6开始,Java程序启动时都会在JVM内部启动一个JMX agent,JMX agent会启动一个MBean server组件,把MBeans(Java平台标准的MBean + 你自己创建 ...

  9. 数据库编程测试机试 QQ

    创建QQ数据库 #创建数据库 CREATE DATABASE QQ #创建表名 并且添加列 DROP TABLE IF EXISTS `dbo.BaseInfo`; CREATE TABLE `stu ...

  10. 3.1 Makefile

    安装make 安装make sudo apt-get install make make -v