[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 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
.
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的更多相关文章
- 【Leetcode_easy】836. Rectangle Overlap
problem 836. Rectangle Overlap solution: class Solution { public: bool isRectangleOverlap(vector< ...
- 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 ...
- 【LeetCode】836. Rectangle Overlap 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/rectangle ...
- #Leetcode# 836. Rectangle Overlap
https://leetcode.com/problems/rectangle-overlap/ A rectangle is represented as a list [x1, y1, x2, y ...
- [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 ...
- 836. Rectangle Overlap 矩形重叠
[抄题]: A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of i ...
- [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 ...
- [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 ...
- [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 ...
随机推荐
- 把旧系统迁移到.Net Core 2.0 日记 (17) --多租户和SoftDelete
在EF Core 2.0版本中出现了全局过滤新特性即HasQueryFilter,它出现的意义在哪里?能够解决什么问题呢? 通过HasQueryFilter方法来创建过滤器能够允许我们对访问特定数据库 ...
- memory prefix out omni,over,out,od,octa ~O
1● omni 全部 ,到处: 2● over 过度,超过,出去,翻转 3● out 超过,过去,过分, 在~之上, 4● od 逆,倒 :加强 的 意思 5● octa 八
- Easyui的datagrid的editor(行编辑器)如何扩展datetimebox类型
在easyui的datagrid扩展方法中添加这样的时间日期(datetimebox)代码块 放在 $.extend($.fn.datagrid.defaults.editors,{datetim ...
- mac 安装Seaslog扩展及SeasLogger应用
首先下载 http://pecl.php.net/package/SeasLog 下载最新解压 cd /SeasLog-2.0.2/SeasLog-2.0.2/ phpize ./configure ...
- python 利用turtle库绘制五角星
# -*- coding: utf-8 –*-import turtleimport math def draw_polygon(aTurtle, size=50, n=3): for i in ra ...
- 01背包问题之2(dp)
01背包问题之2 有n个物品,重量和价值分别为wi和vi,从这些物品中挑选出重量不超过W的物品,求所有挑选方案中物品价值总和的最大值 限制条件: 1 <= n <= 100; 1 < ...
- 将excel数据分块多线程导入
参考链接:http://blog.csdn.net/liqi_q/article/details/53032027
- IDEA使用GitHub托管代码
该方法基本也适用于JetBrains公司的其他IDE产品,如phpStorm,PyCharm等. 首先,在github官网注册一个账号,参考:http://stormzhang.com/github/ ...
- [Leetcode 376]摇摆序列 Wiggle Subsequence
[题目] A sequence of numbers is called a wiggle sequence if the differences between successive numbers ...
- php随手记
引用(&)是变量的别名,而不是指针,可用unset(变量名)把此变量的别名注销掉,等于没有声明此变量. @为错误抑制符,可以用在任何表达式前面. ``为命令操作符,可以执行系统命令. inst ...