[leetcode] Rectangle Area
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.
Special thanks to @mithmatt for adding this problem, creating the above image and all test cases
class Solution
{
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H)
{
int x1 = A > E ? A : E;
int y1 = B > F ? B : F;
int x2 = C > G ? G : C;
int y2 = D > H ? H : D; int x = x2 - x1, y = y2 - y1;
int s = ;
if(x> && y>)
s = x * y; return (C-A)*(D-B)+(G-E)*(H-F) - s;
}
};
[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
Description:https://leetcode.com/problems/rectangle-area/ public class Solution { public int compute ...
- LeetCode Rectangle Area (技巧)
题意: 分别给出两个矩形的左下点的坐标和右上点的坐标,求他们覆盖的矩形面积? 思路: 不需要模拟,直接求重叠的部分的长宽就行了.问题是如果无重叠部分,注意将长/宽给置为0. class Solutio ...
- [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 ...
随机推荐
- MVC学习中遇到问题
1:无法连接到localdb数据库 解决方案:下载localdb安装软件 2:运行程序时提示数据库已存在,请更改连接名 解决方案:因为在两个不同的解决方案中使用了同样的连接字符串造成生成了同样的数据库 ...
- 在JAVA和android中常用的单列模式
在很多开发中,项目为了节约资源,都把一个类的构造函数变为私有化,这样整个项目中就不能创建多个实例,这样的方法我们称为单例模式 现在通过代码来简介下这个单例模式: 在新建一个java项目后,创建一个实体 ...
- Transact-SQL 示例 - 使用脚本备份数据库的示例
在常规的数据库开发与维护的过程中,常常需要对数据库进行数据备份,最入门的办法就是使用SSMS图形化界面提供的数据库备份向导一步一步操作进行备份,这种方式虽然简单快捷但是日子久了就会觉得重复且繁琐.下面 ...
- Socket.IO 1.0 正式发布,快速可靠的实时引擎
Socket.IO 是目前 Web 领域最火的实时引擎,用于实现基于事件的双向实时的通信.它适用于任何平台,浏览器或设备,专注于可靠性和速度.您可以将数据推送到客户端,并获得实时的计数,日志或图表. ...
- [python]抽象方法
抽象方法 我的理解抽象方法就是:父类的一个方法,继承的所有子类都必须要实现这个方法,否则报错. 举例说明 class Base(object): def _method(self): raise No ...
- Cocos2d-x数据存储
分别是使用UserDefault,内置文件管理和sqlite3数据库的一般方式: 主要代码: bool DataScene::init(){ if (!Layer::init()){ return f ...
- 学习android开发笔记
最近重点看了几个android工程的源代码,有几点疑问 1:为什么android客户端游戏要开启n个线程,而且通常每个线程的操作只有i++: 2:为什么很多列表在游戏逻辑和绘制逻辑里没有做同步: 3: ...
- c# XML序列化与反序列化
c# XML序列化与反序列化 原先一直用BinaryFormatter来序列化挺好,可是最近发现在WinCE下是没有办法进行BinaryFormatter操作,很不爽,只能改成了BinaryWrite ...
- 使用MinGW 编译 iconv 库
原文链接: http://www.code-by.org/viewtopic.php?f=54&t=166 GNU页面 http://ftp.gnu.org/pub/gnu/libiconv/ ...
- web api返回格式小结
web api返回格式小结: 1.默认是返回xml格式数据,如果需要返回json格式,需要在Global.asax中加入: GlobalConfiguration.Configuration.Form ...