leetcode 签到 836. 矩形重叠
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/
思路:
假设
rec1:[0,0,2,2]->[x10,y11,x12,y13]
(x10即rec1的第1位)
rec2:[1,1,3,3]->[x20,y21,x22,y23]
列举出不匹配的情况:
x轴:x22<=x10或者x12<=x20
y轴:y11<=y23或者y21<=y13
代码
class Solution:
def isRectangleOverlap(self, rec1, rec2) -> bool:
if rec1[1]>=rec2[3] or(rec1[0]>=rec2[2] or rec2[0]>=rec1[2]):
return False
elif rec2[1]>=rec1[3] or (rec1[0]>=rec2[2] or rec2[0]>=rec1[2]):
return False
else:
return True
a=Solution()
rec1 = [0,0,2,2]
rec2 = [1,1,3,3]
print(a.isRectangleOverlap(rec1,rec2))
leetcode 签到 836. 矩形重叠的更多相关文章
- Java实现 LeetCode 836 矩形重叠(暴力)
836. 矩形重叠 矩形以列表 [x1, y1, x2, y2] 的形式表示,其中 (x1, y1) 为左下角的坐标,(x2, y2) 是右上角的坐标. 如果相交的面积为正,则称两矩形重叠.需要明确的 ...
- LeetCode 836. 矩形重叠
题目链接:https://leetcode-cn.com/problems/rectangle-overlap/ 矩形以列表 [x1, y1, x2, y2] 的形式表示,其中 (x1, y1) 为左 ...
- [LeetCode] Rectangle Overlap 矩形重叠
A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bot ...
- [Swift]LeetCode836. 矩形重叠 | Rectangle Overlap
A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bot ...
- 836. Rectangle Overlap 矩形重叠
[抄题]: A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of i ...
- [LeetCode] Rectangle Area 矩形面积
Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...
- [LeetCode] Non-overlapping Intervals 非重叠区间
Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...
- [LeetCode] Image Overlap 图像重叠
Two images A and B are given, represented as binary, square matrices of the same size. (A binary ma ...
- libgdx判断矩形重叠碰撞
有两种方式. 1. 排除法,排除四种不可能重叠的情况就是了. public static boolean IsOverlap( Rectangle rect1, Rectangle rect2 ){ ...
随机推荐
- 在没有APP的125年前 印度的外卖小哥是这样送餐
说到印度,你想到的是什么?咖喱.歌舞剧.开挂的火车?通通不是,我今天要说的是他们的外卖小哥,在印度如同"神"一般的存在.其实印度人不叫这批人为外卖小哥,而称他们为dabbawala ...
- 修改android项目sdk版本
1.右键单击项目--->properties---->Resource----->Android在Project Bulid Target对话框中选择你需要的Android版本.2. ...
- 点击穿透bug · Jaywii
微信点击穿透Bug 问题描述:在移动端为了去除点击延迟引入了fast-click,然而在房贷计算器的开发中遇到了这样一个bug,用户点击了select之后,微信在弹出选择器之后会瞬间因为约300ms的 ...
- Rust入坑指南:朝生暮死
今天想和大家一起把我们之前挖的坑再刨深一些.在Java中,一个对象能存活多久全靠JVM来决定,程序员并不需要去关心对象的生命周期,但是在Rust中就大不相同,一个对象从生到死我们都需要掌握的很清楚. ...
- unittest实战(四):用例编写
import yamlimport unittestfrom selenium import webdriverimport timefrom ddt import ddt, data, unpack ...
- 关于IT培训机构的个人看法
1.前言 缘分与巧合,最近接触比较多的培训机构出来的人,以及看过关于培训机构的文章和问答.虽然没在培训机构上过课,但是接触过很多培训机构出来的人,也看过一些培训机构的课程.关于培训机构,我也有自己的看 ...
- Slog27_支配vue框架初阶项目之博客网站-样式居中
ArthurSlog SLog-27 Year·1 Guangzhou·China July 30th 2018 GitHub 掘金主页 简书主页 segmentfault 没有写够足够的代码量,想成 ...
- 2020年,大厂常问iOS面试题汇总!
Runloop & KVO runloop app如何接收到触摸事件的 为什么只有主线程的runloop是开启的 为什么只在主线程刷新UI PerformSelector和runloop的关系 ...
- Python基础-两个乒乓球队进行比赛,各出三人。
两个乒乓球队进行比赛,各出三人.甲队为a,b,c三人,乙队为x,y,z三人.已抽签决定比赛名单.有人向队员打听比赛的名单.a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单. L1 = [ ...
- 内网渗透之权限维持 - MSF与cs联动
年初六 六六六 MSF和cs联动 msf连接cs 1.在队伍服务器上启动cs服务端 ./teamserver 团队服务器ip 连接密码 2.cs客户端连接攻击机 填团队服务器ip和密码,名字随便 ms ...