[LeetCode] 836. Rectangle Overlap_Easy
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:
- Both rectangles
rec1
andrec2
are lists of 4 integers. - All coordinates in rectangles will be between
-10^9
and10^9
.
这个题目用逆向思维, 去想怎么样不overlap, 所以rec1可以在left, right, up, down 四个方向.
Code
class Solution(object):
def isRectangleOverlap(self, rec1, rec2):
"""
:type rec1: List[int]
:type rec2: List[int]
:rtype: bool
"""
##Solution1
return not (rec1[3] <= rec2[1] or #left
rec1[1] >= rec2[3] or # right
rec1[0] >= rec2[2] or #up
rec1[2] <= rec2[0]) #down
[LeetCode] 836. Rectangle Overlap_Easy的更多相关文章
- #Leetcode# 836. Rectangle Overlap
https://leetcode.com/problems/rectangle-overlap/ A rectangle is represented as a list [x1, y1, x2, y ...
- leetcode Maximal Rectangle 单调栈
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4052721.html 题目链接:leetcode Maximal Rectangle 单调栈 ...
- leetcode Largest Rectangle in Histogram 单调栈
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4052343.html 题目链接 leetcode Largest Rectangle in ...
- [LeetCode] Largest Rectangle in Histogram O(n) 解法详析, Maximal Rectangle
Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar height ...
- 【Leetcode_easy】836. Rectangle Overlap
problem 836. Rectangle Overlap solution: class Solution { public: bool isRectangleOverlap(vector< ...
- 【LeetCode】836. Rectangle Overlap 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/rectangle ...
- [LeetCode&Python] Problem 836. Rectangle Overlap
A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bot ...
- [LeetCode] Perfect Rectangle 完美矩形
Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover o ...
- [LeetCode] Smallest Rectangle Enclosing Black Pixels 包含黑像素的最小矩阵
An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black ...
随机推荐
- 【SPMF开源数据挖掘平台入门】MaxSP算法使用说明
前段时间,由于项目中用到了序列挖掘的算法,师兄推荐我用用SPMF.在此做个记录. 首先简单介绍一下SPMF: SPMF是一个采用Java开发的开源数据挖掘平台. 它提供了51种数据挖掘算法实现,用于: ...
- 解决Win7启动时出现“windows未能启动。原因可能是最近更改了硬件或软件”的问题
昨天公司终于大发慈悲,统一更换电脑配置,终于要摆脱“手扶拖拉机”的时代了,赶上“动车时代”了.不过不想换硬盘,因为重新要安装太多东西,环境配置一大堆,所以就硬盘没有换,不过当我开机启动的时候,悲剧发生 ...
- LeetCode 42 Trapping Rain Water(积水体积)
题目链接: https://leetcode.com/problems/trapping-rain-water/?tab=Description Problem: 根据所给数组的值,按照上图的示意 ...
- Atom使用插件精选
小颖之前公司的大哥推荐小颖用的编辑器是atom,之前都是他给小颖了一个atom插件安装列表,小颖电脑出了点问题,所以后来小颖把那弄丢了,小颖重装atom后,就不知道要安装什么插件,所以也百度了很多,今 ...
- U盘安装Centos7.1操作系统的问题记录
需要的软硬件环境>>>>>>>>>>>>>>>>>1.服务器(笔者用的笔记本).U盘2.Cento ...
- Notepad++如何关闭最近打开的文件的历史记录功能
Notepad++是Windows 操作系统下的一套非常有特色的自由软件的纯文字编辑器(许可证:GPL),有完整的中文化接口及支持多国语言编写的 功能(UTF8 技术).它的功能比Windows中的N ...
- iOS教程:Core Data数据持久性存储基础教程
目录[-] 创建Core Data工程 创建数据模型 测试我们的数据模型 来看看SQL语句的真面目 自动生成的模型文件 创建一个表视图 之后看些什么? 就像我一直说的,Core Data是iOS编程, ...
- jquery的$.each如何退出循环和退出本次循环
https://api.jquery.com/jQuery.each/ We can break the $.each() loop at a particular iteration by maki ...
- jsp页面获取参数的方法(url解析、el表达式赋值、session取值)【原创】
最近使用myEclispse做网站,使用jsp+js+css做页面,网站中常用到从列表进入详情页面的跳转,下面对详情页面的值填充方式做一个简单总结: 1.url中使用request获取参数 jsp上方 ...
- Python 基础知识(一)
1.Python简介 1.1.Python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中文名字:龟叔)为了在阿姆斯特丹打发时 ...