#Leetcode# 836. Rectangle Overlap
https://leetcode.com/problems/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
rec1andrec2are lists of 4 integers. - All coordinates in rectangles will be between
-10^9and10^9.
代码:
class Solution {
public:
bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) {
int A = rec1[0], B = rec1[1], C = rec1[2], D = rec1[3];
int E = rec2[0], F = rec2[1], G = rec2[2], H = rec2[3];
if (E >= C || F >= D || B >= H || A >= G) return false;
return true;
}
};
#Leetcode# 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&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] 836. Rectangle Overlap_Easy
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 ...
- 836. Rectangle Overlap
class Solution { public: bool isRectangleOverlap(vector<int>& rec1, vector<int>& ...
- [LeetCode] 850. Rectangle Area II 矩形面积之二
We are given a list of (axis-aligned) rectangles. Each rectangle[i] = [x1, y1, x2, y2] , where (x1, ...
- [LeetCode] 223. Rectangle Area 矩形面积
Find the total area covered by two rectilinearrectangles in a 2D plane. Each rectangle is defined by ...
随机推荐
- May 26. 2018 Week 21st Saturday
Do what you say, say what you do. 做你说过的,说你能做的. Be honest to yourself, and be honest to those people ...
- update layer tree导致页面卡顿
前因 今天检查一个vue页面问题,就是在切换Tab时候(某些win10电脑),页面会卡顿一段很长的时间,短则3秒,长则十几秒,这个体验非常糟糕,于是我着手寻找其中原因. 概况 这个vue页面的元素非常 ...
- C#基础知识之泛型集合转换为DataTable
在做项目中,遇到了将集合转换为DataTable的使用,在网上看了资料,在这里记录下来,分享. using System; using System.Collections.Generic; usin ...
- POJ 3970(最小公倍数LCM)
版权声明:Site:https://skyqinsc.github.io/ https://blog.csdn.net/u013986860/article/details/26182055 知 ...
- UVA1626-Brackets sequence(动态规划基础)
Problem UVA1626-Brackets sequence Time Limit: 4500 mSec Problem Description Input The input begins w ...
- Python requests上传文件demo
#!/usr/bin/env python # -*- coding: utf-8 -*- import requests headers = {'uuid': '5cb572b7-c0a7-4d90 ...
- Python:Day51 web框架
from wsgiref.simple_server import make_server def application(environ, start_response): start_respon ...
- 五.JQuary 实例
需要引入jquery.js文件 script type="text/javascript" src="../js/jquery-3.2.1.js">< ...
- arduino json 解析
#include <ArduinoJson.h> void setup() { Serial.begin(9600); DynamicJsonDocument jsonBuffer(200 ...
- 解决 Vim 的 quickfix 插件错误信息乱码问题
将以下代码插入 vim 配置文件即可, function! QfMakeConv() let qflist = getqflist() for i in q ...