【一天一道LeetCode】#223. Rectangle Area
一天一道LeetCode
本系列文章已全部上传至我的github,地址:ZeeCoder‘s Github
欢迎大家关注我的新浪微博,我的新浪微博
欢迎转载,转载请注明出处
(一)题目
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.
(二)解题
题目大意:求两个矩形总的覆盖面积。
解题思路:判断两个数组不重叠,满足C<=E||G<=A||F>=D||B>=H,
如果重叠求重叠面积:(min(C,G)-max(A,E))*(min(D,H)-max(B,F))。
下面是代码:
class Solution {
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int total = (C-A)*(D-B)+(G-E)*(H-F);
if(C<=E||G<=A||F>=D||B>=H) return total;//不重叠
return total - (min(C,G)-max(A,E))*(min(D,H)-max(B,F));//重叠
}
};
【一天一道LeetCode】#223. Rectangle Area的更多相关文章
- [LeetCode] 223. Rectangle Area 矩形面积
Find the total area covered by two rectilinearrectangles in a 2D plane. Each rectangle is defined by ...
- Java for LeetCode 223 Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...
- (easy)LeetCode 223.Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...
- Java [Leetcode 223]Rectangle Area
题目描述: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is def ...
- [LeetCode]223. Rectangle Area矩形面积
/* 像是一道数据分析题 思路就是两个矩形面积之和减去叠加面积之和 */ public int computeArea(int A, int B, int C, int D, int E, int F ...
- LeetCode : 223. Rectangle Area
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABRQAAAQ0CAYAAAAPPZBqAAAMFGlDQ1BJQ0MgUHJvZmlsZQAASImVlw
- LeetCode 223 Rectangle Area(矩形面积)
翻译 找到在二维平面中两个相交矩形的总面积. 每一个矩形都定义了其左下角和右上角的坐标. (矩形例如以下图) 如果,总占地面积永远不会超过int的最大值. 原文 分析 这题前天试过,写了一堆推断.终究 ...
- 【刷题-LeetCode】223. Rectangle Area
Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...
- [LeetCode] 850. Rectangle Area II 矩形面积之二
We are given a list of (axis-aligned) rectangles. Each rectangle[i] = [x1, y1, x2, y2] , where (x1, ...
随机推荐
- of_alias_get_id 函数与设备树中aliases节点的关系【转】
转自:https://blog.csdn.net/qq_30145093/article/details/78053823?locationNum=10&fps=1 转自http://www. ...
- C++变量和基本类型——2.3.1引用
引用:为对象起了另外一个名字,通常将申明符写成&d的形式来定义引用类型,其中d是申明的变量名: int ival =1024; int &refVal=ival 一般在初始化变量时,初 ...
- 笔记8 AOP练习2
场景描述: 一张唱片有好多磁道,假设每个磁道只有一首歌,现在需要记录每首歌的播放次数,然后输出. 主要业务:歌曲播放 辅助功能:记录播放次数(切面) 1.创建唱片接口,CompactDiscs.jav ...
- C# winform中自定义精确定时器(经测试稳定可靠)
原C#的定时器时间越长,误差越大. 在主动请求设备数据的使用,使用C#的几种自带定时器导致每天都会丢失几条数据. 经测试使用自定义的定时器可完全解决此问题. 使用方法: MillisecondTime ...
- java 第三次作业
(一)学习总结 1.阅读下面程序,分析是否能编译通过?如果不能,说明原因.应该如何修改?程序的运行结果是什么?为什么子类的构造方法在运行之前,必须调用父 类的构造方法?能不能反过来? class Gr ...
- 博客迁移,新地址:bfsan.github.io
博客的新内容会在新地址发布(暂时),后期可能会考虑做一个整合同步.
- python字典无限遍历
#无限遍历dict,通过key获取value,嵌套字典存在多个相同的key,可获取多个key class getValues(object): def __init__(self): pass #无限 ...
- Python小代码_14_交换 2 个变量的 3 种方式
a = 4 b = 5 #第一种 c = a a = b b = c print(a, b) #输出结果 #5 4 #第二种 a = a + b b = a - b a = a - b print(a ...
- Openlayers3学习心得(初识)
最近刚辞了原来的那家公司,准备新找一份工作.其中有个公司要求会Openlayers3.一看到这个要求,就知道公司业务涉及地图图表比较多. Openlayers本身是一个基于GIS地图相关的功能丰富的J ...
- --save-dev 和 --save的区别
1. 我们在使用npm install xx --save-dev / --save安装模块或插件的时候,会将他们写入到 package.json 文件,那到底有什么区别呢? --save-dev:会 ...