Find the total area covered by two rectilinear rectangles in a 2D plane.
Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.
![【LeetCode】223 - Rectangle Area 【LeetCode】223 - Rectangle Area](https://image.shishitao.com:8440/aHR0cDovL2Jic21heC5pa2FmYW4uY29tL3N0YXRpYy9MM0J5YjNoNUwyaDBkSEJ6TDJ4bFpYUmpiMlJsTG1OdmJTOXpkR0YwYVdNdmFXMWhaMlZ6TDNCeWIySnNaVzF6WlhRdmNtVmpkR0Z1WjJ4bFgyRnlaV0V1Y0c1bi5qcGc%3D.jpg?w=700&webp=1)
Assume that the total area is never beyond the maximum possible value of int.
Solution: 两长方形面积之和减去重合部分面积;当A>=G或C<=E或B>=H或D<=F时,两长方形不相交;
class Solution {
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int width,height;
if(A>=G||C<=E||B>=H||D<=F){
width=;
height=;
}else{
if(A<=E)
width=min(C-E,G-E);
else
width=min(C-A,G-A); if(B<=F)
height=min(D-F,H-F);
else
height=min(D-B,H-B);
}
return (C-A)*(D-B)+(G-E)*(H-F)-height*width;
}
};
【LeetCode】223 - Rectangle Area的更多相关文章
-
【LeetCode】223. Rectangle Area 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/rectangl ...
-
【刷题-LeetCode】223. Rectangle Area
Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...
-
【一天一道LeetCode】#223. Rectangle Area
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Find th ...
-
【leetcode】963. Minimum Area Rectangle II
题目如下: Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from ...
-
【LeetCode】836. Rectangle Overlap 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/rectangle ...
-
【leetcode❤python】 223. Rectangle Area
#-*- coding: UTF-8 -*-#先判断是否有重叠class Solution(object): def computeArea(self, A, B, C, D, E, F, G, ...
-
【LeetCode】963. Minimum Area Rectangle II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 线段长+线段中心+字典 日期 题目地址:https: ...
-
【LeetCode】939. Minimum Area Rectangle 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 确定对角线,找另外两点(4sum) 字典保存出现的x ...
-
【leetcode】939. Minimum Area Rectangle
题目如下: Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from t ...
随机推荐
-
centos6.5安装lnmp环境
1.安装nignx的源,默认cenots6没有的. rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-cent ...
-
软件测试第四周--关于int.parse()的类型转换问题
先来归纳一下我们用过的所有类型转换方法: 1. 隐式类型转换,即使用(int) 直接进行强制类型转换.这种方法的优点是简单粗暴,直接指定转换类型,没有任何保护措施,所以也很容易抛出异常导致程序崩溃.当 ...
-
《Inside UE4》-1-基础概念
<Inside UE4>-1-基础概念 InsideUE4 创建测试项目 接上文的准备工作,双击生成的UE4Editor.exe,选择创建测试C++空项目Hello(以后的源码分析 ...
-
学习Django
1.安装 命令:pip install Django 安装慢且有异常:HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed ...
-
二、	C#调用存储过程
个人比较喜欢使用第二种传递参数的方法 1. 调用的方法 public DataTable ExceStoredProcedure (string strCom, SqlParameter[] comm ...
-
MySQL 使用索引扫描来做排序
MySQL有两种方式可以生成有序的结果:通过排序操作:或者按照索引顺序扫描:如果EXPLAIN 出来的结果的type列的值为“index”,则说明MySQL使用了索引扫描来做排序(不要和Extra列的 ...
-
[Swust OJ 581]--彩色的石子(状压dp)
题目链接:http://acm.swust.edu.cn/problem/0581/ Time limit(ms): 1000 Memory limit(kb): 65535 Descriptio ...
-
spring 标签
*/ @Slf4j @Service public class RetryService { @Autowired private MqConfig mqConfig; /** * 如果网络连接失败, ...
-
SVN版本冲突问题
--------------------siwuxie095 SVN 版本冲突问题 如:Jack 和 Mary 从仓库中将项目下载到本地,然后 Jack 修改了 项目中的一个文件,并上传到仓库中,之后 ...
-
C++ 顺序表实现
线性表就是字面上的意思, 顺序表是线性表基于数组的一种实现, “顺序”这个名字怎么来的并不清楚,可以勉强解释为“存储地址是连续.顺序的”. 另外两种线性表实现分别是“基于链表”和“散列存储”. 顺序表 ...