python【力扣LeetCode算法题库】836- 矩形重叠
2020-03-23 18:35
721 查看
- 矩形重叠
矩形以列表 [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 之间。
两个重叠的矩形一定有如下关系:
rec1的最左一定小于rec2的最右,rec2的最左一定小于rec1的最右
rec1的最下一定小于rec2的最上,rec2的最上一定小于rec1的最下
class Solution(object): def isRectangleOverlap(self, rec1, rec2): """ :type rec1: List[int] :type rec2: List[int] :rtype: bool """ x1, y1, x2, y2 = rec1 x3, y3, x4, y4 = rec2 return (x4 - x1) * (x2 - x3) > 0 and (y4 - y1) * (y2 - y3) > 0
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- python【力扣LeetCode算法题库】876- 链表的中间结点
- python【力扣LeetCode算法题库】945- 使数组唯一的最小增量
- python【力扣LeetCode算法题库】365- 水壶问题(裴蜀等式)
- python【力扣LeetCode算法题库】面试题40- 最小的k个数
- python【力扣LeetCode算法题库】409-最长回文串(数学 计数器)
- Python Leetcode(836.矩形重叠)
- python写算法题:leetcode: 21. Merge Two Sorted Lists
- python写算法题:leetcode: 31. Next Permutation
- [算法] LeetCode 1.两数之和(python)
- 力扣(leetcode 6)z形变换 python
- [算法Rust,Go,Python,JS实现)]LeetCode之20-有效括号匹配
- [算法Rust,Go,Python,JS实现)]LeetCode之09-回文数
- 【python】【leetcode】【算法题目344—Reverse String】
- 力扣169题:多数元素,Boyer-Moore投票算法学习笔记,python实现
- python写算法题:leetcode: 22. Generate Parentheses
- python写算法题:leetcode: 23. Merge k Sorted Lists
- 【python】【leetcode】【算法题目4—Median of Two Sorted Arrays】
- 【python】【leetcode】【算法题目6—ZigZag Conversion】
- python写算法题:leetcode: 26. Remove Duplicates from Sorted Array
- 【python】【leetcode】【算法题目9—Palindrome Number】