LeetCode Rectangle Area (技巧)
题意:
分别给出两个矩形的左下点的坐标和右上点的坐标,求他们覆盖的矩形面积?
思路:
不需要模拟,直接求重叠的部分的长宽就行了。问题是如果无重叠部分,注意将长/宽给置为0。
class Solution {
public:
int getArea(int A,int B,int C,int D){return (C-A)*(D-B);}
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H)
{
int x= min(C,G)>max(A,E)? min(C,G)-max(A,E) : ;
int y= min(D,H)>max(B,F)? min(D,H)-max(B,F) : ;
return getArea(A,B,C,D) + getArea(E,F,G,H) - x*y;
}
};
AC代码
LeetCode Rectangle Area (技巧)的更多相关文章
- [LeetCode] Rectangle Area 矩形面积
Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...
- [leetcode] Rectangle Area
Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...
- LeetCode——Rectangle Area
Description:https://leetcode.com/problems/rectangle-area/ public class Solution { public int compute ...
- [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 ...
- LeetCode 223. 矩形面积(Rectangle Area)
223. 矩形面积 223. Rectangle Area 题目描述 在二维平面上计算出两个由直线构成的矩形重叠后形成的总面积. 每个矩形由其左下顶点和右上顶点坐标表示,如图所示. LeetCode2 ...
- 【leetcode】Contains Duplicate & Rectangle Area(easy)
Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your funct ...
- 【刷题-LeetCode】223. Rectangle Area
Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...
- [LeetCode] Rectangle Overlap 矩形重叠
A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bot ...
随机推荐
- [工作技能]SVN
有的时候SVN上传txt文本文件,会报是bin文件的错误,解决方式是在.subversion文件夹下的config文件中加这么一句 *.txt = svn:mime-type=text/plain;s ...
- linux web php 安全相关设置
1 隐藏apache 或者 nginx的版本号 2 隐藏php的版本号 3 php 程序做好基本的防注入 xss之类的攻击 4 禁用PHP一些危险的函数 比如 phpinfo.system之类的 5 ...
- Nginx 在windows下配合iis搭建负载均衡过程 [转]
因为项目遇到大量图片存储问题,虽然现在我们图片还不是很多(目前在1T上下,预计增长速度每年1.3倍的增长速度),自己在思考如何有效地存储大量图片时,查找一些资料,看到了,有人使用 Nginx搭建服务器 ...
- JavaOne 2016——观众得以一睹JShell的威力
导读 在JavaOne 2016的主题演讲中,Java平台组的首席架构师Mark Reinhold指出Java 9并不仅仅是Jigsaw,针对Java 9,一共包含了85个JEP.我在这里会关注一个他 ...
- ie8解决F12问题
工作中,突然电脑上的ie8按F12掉不出来了,一直显示最小化.于是在网上找了很多方法,按这种方法可以解决问题. 1.cmd+r,输入regedit,调出 注册表编辑器. 2.HKEY_CURRENT_ ...
- 10 notorious computer virus
The history of computer virus is the same as computer history. With more and more powerful computers ...
- C++-多重继承的注意点
1, 钻石型多重继承如果不想要底部的类有重复的变量,则需要声明为virtual继承 class File{...}; class InputFile: virtual public File{..}; ...
- 11个Linux基础面试问题
Q.1: Linux 操作系统的核心是什么? Shell Kernel Command Script Terminal 答: 内核(Kernel)是Linux 操作系统的核心.Shell是一个命令行解 ...
- Dom事件初步了解
1.事件流 事件流可以分为两种:事件冒泡和事件捕获 1. 事件冒泡就是从目标元素一直冒泡到根元素html(IE和DOM浏览器都有) 2. 事件捕获就是从根元素到目标元素(DOM浏览器支持) 2.事件处 ...
- AS3事件流机制
事件流: 显示对象,深度 MouseEnabled,MouseChildren:显示对象,同层次(父容器为同一对象)遮挡问题