[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
rec1andrec2are lists of 4 integers. - All coordinates in rectangles will be between
-10^9and10^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 ...
随机推荐
- 三个 CSS 预处理器(框架):Sass、LESS 和 Stylus
CSS 预处理器技术已经非常的成熟,而且也涌现出了越来越多的 CSS 的预处理器框架.本文向你介绍使用最为普遍的三款 CSS 预处理器框架,分别是 Sass.Less CSS.Stylus. 首先我们 ...
- 【本周主题】第一期:JavaScript单线程与异步
相信下边这个图一定都不陌生,本周就围绕这张图深入了解下js代码执行时的来龙去脉. 一.JavaScript是单线程的 2018-11-19 21:21:21 周一 js本质是单线程的.这一特性是jav ...
- 阅读代码工具:Visual Studio Code
打开一个文件夹,直接阅读,体验还不错 版本: 1.25.1提交: 1dfc5e557209371715f655691b1235b6b26a06be日期: 2018-07-11T15:43:11.471 ...
- Debian的自动化安装(DEBIAN_FRONTEND)
Debian 安装程序的参数 安装系统确认一些附加的引导参数 debconf/priority 这些参数设置将设置显示的信息为为最低的级别. 缺省安装使用 debconf/priority=high ...
- AFNetWork 简单实用demo
NSString *postUrl = @"http://www.huway.com/api_index?module=event&action=topads"; NSDi ...
- python中filter(),map()和reduce()的用法及区别
先看filter()方法 print(list(filter(lambda n : n % 2 == 1, range(20))))# 结果 [1, 3, 5, 7, 9, 11, 13, 15, 1 ...
- mongodb的学习笔记一(集合和文档的增删改查)
1数据库的增删改查 一.增加一个数据库: use blog-----切换到指定的数据库,如果数据库不存在,则自动创建该数据库(新建的数据库,如果没有存储对应的集合,是不会显示出来的) 二.删除一个数据 ...
- 2018-2019-2 20165330《网络对抗技术》Exp6 信息搜集与漏洞扫描
目录 基础问题 相关知识 实验目的 实验内容 实验步骤 实验总结与体会 实验目的 掌握信息搜集的最基础技能与常用工具的使用方法. 返回目录 实验内容 各种搜索技巧的应用 使用搜索引擎 搜索网址目录结构 ...
- cordova-ios 升级到4.4.0 无法真机跑iOS8 报错: dyld`dyld_fatal_error: -> 0x120085088 <+0>: brk #0x3
项目进入测试阶段,马上要上线了,同事拿了自己的iOS8系统5s跑真机,无缘无故报错,之前跑她的手机完全没有问题的.Xcode 8.x中最低部署版本是iOS8.0,按理说完全能够跑真机的. 但是报了一个 ...
- 使用TensorFlow Serving优化TensorFlow模型
使用TensorFlow Serving优化TensorFlow模型 https://www.tensorflowers.cn/t/7464 https://mp.weixin.qq.com/s/qO ...