【LeetCode】223 - Rectangle Area
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.

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 ...
随机推荐
- JSP下载txt 和 Excel两种文件
JSP下载txt 和 Excel两种文件 jsp 下载txt文件和excel文件 jsp 下载txt文件和excel文件 最近做了个用jsp下载的页面 将代码贴出来 权作记录吧 1 下载txt文件 ...
- ajax 一个 gbk 目标后内容乱码的解决方案
ajax 一个 gbk 目标后,如果内容出现乱码,说明服务器在送出内容时没有指定 charset,ajax 对于没有指定 charset 的 response 默认以 utf-8 来处理,所有出现乱码 ...
- Kruskal
算法描述:克鲁斯卡尔算法需要对图的边进行访问,所以克鲁斯卡尔算法的时间复杂度只和边又关系,可以证明其时间复杂度为O(eloge). 算法过程: 1.将图各边按照权值进行排序 2找出权值最小的边,(条件 ...
- poj 1017 Packets 裸贪心
Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43189 Accepted: 14550 Descrip ...
- MongoDB 学习笔记(三) MongoDB (replica set) 集群配置
MongoDB Replica Sets的结构类似于以集群,完全可以把他当成一个集群,因为他确实与集群实现的作用是一样的:如果其中一个节点出现故障,其他的节点会马上将业务接管过来.而无需停机操作 Mo ...
- laravel Event执行顺序
laravel一大特色就是event事件系统.一般首先要listen一个事件,随后fire那个事件,这时执行路径将会调用event handler,返回后继续执行.例如: Event::listen( ...
- eclipse中字母大小写转换快捷键
ctrl+shift+x 转为大写 ctrl+shift+y 转为小写
- 基于Flume的美团日志收集系统(二)改进和优化
在<基于Flume的美团日志收集系统(一)架构和设计>中,我们详述了基于Flume的美团日志收集系统的架构设计,以及为什么做这样的设计.在本节中,我们将会讲述在实际部署和使用过程中遇到的问 ...
- UVa 10048 Audiophobia【Floyd】
题意:给出一个c个点,s条边组成的无向图,求一点到另一点的路径上最大权值最小的路径,输出这个值 可以将这个 d[i][j]=min(d[i][j],d[i][k]+d[k][j]) 改成 d[i][j ...
- 百度编辑器解决span被过滤, 自动加P标签
editor_all.js: 自动加P标签去除: enterTag: 'p', 改成: enterTag: '', span被过滤: //从编辑器出去的内容处理 me.addOutputR ...