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. IIS隐藏版本号教程(Windows Server 2003)

    1.下载Urlscan https://www.microsoft.com/en-us/search/DownloadResults.aspx?q=URLScan(总下载页面) https://dow ...

  2. Vmware tools install

    Vmware tools 1◆ 下载 2◆ diagram   Ifcfg-eth0   =====>关闭防火墙 systemctl stop firewalld.service   ===== ...

  3. Linux gcc getcwd()的实现 zhuan

      通过getcwd()可以获取当前工作目录. 1 #include <unistd.h> 2 3 char *getcwd(char *cwdbuf, size_t size);

  4. CAD绘制室外平台步骤5.3

    1.在平面上用直线划出台阶范围. “工具”“曲线工具”“线变复线”选择这几条线,它们就变成了一条线. “三维建模”“造型对象”“平板”选择这条封闭的线,回车,选择相邻门窗柱子等,回车输入平台厚度如“- ...

  5. POJ 1936 All in All 匹配, 水题 难度:0

    题目 http://poj.org/problem?id=1936 题意 多组数据,每组数据有两个字符串A,B,求A是否是B的子串.(注意是子串,也就是不必在B中连续) 思路 设置计数器cnt为当前已 ...

  6. vue-10-混合

    混合对象可以包含任意组件选项, // 定义一个混合对象 var myMixin = { created: function () { this.hello() }, methods: { hello: ...

  7. 6.1 C++ string类型变量的定义以及输入与输出

    参考:http://www.weixueyuan.net/view/6389.html 总结: 在C++中提供了一个型的内建数据类型string,该数据类型可以替代C语言中char数组. 与C风格的c ...

  8. Linux下安装微信(转)

    扩展:https://www.cnblogs.com/dunitian/p/9124806.html 安装过程如下: 1.下载最新版本tar.gz压缩包https://github.com/geeee ...

  9. win 10 初始环境变量

    有时用户会修改Win10系统的环境变量,改到后面原来是什么的也记不得了,想要改回去还要去别的电脑查看,这里转载下Win10 64位环境变量的默认初始值. 附:打开环境变量方法:电脑左下右键——系统—— ...

  10. 安装连接mysql8时候遇到的问题以及解决(转)

    官网下载mysql8的安装包: https://dev.mysql.com/downloads/ 下一步安装即可. mysql8增加了传说中的安全性校验 遇到的几个问题: 1.natcat连接不上.参 ...