(easy)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.
解法:两个矩形面积相加,有重叠部分,则减去重叠部分。重叠部分面积计算。左点的最大值,与右点的最小,比较
代码如下:
public class Solution {
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int res=(C-A)*(D-B)+(G-E)*(H-F);
int A1=Math.max(A,E);
int B1=Math.max(B,F);
int C1=Math.min(C,G);
int D1=Math.min(D,H);
if(A1>=C1 || B1>=D1) return res;
return res-(C1-A1)*(D1-B1);
}
}
运行结果:
(easy)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 ...
- 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
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABRQAAAQ0CAYAAAAPPZBqAAAMFGlDQ1BJQ0MgUHJvZmlsZQAASImVlw
- LeetCode 223 Rectangle Area(矩形面积)
翻译 找到在二维平面中两个相交矩形的总面积. 每一个矩形都定义了其左下角和右上角的坐标. (矩形例如以下图) 如果,总占地面积永远不会超过int的最大值. 原文 分析 这题前天试过,写了一堆推断.终究 ...
- [LeetCode]223. Rectangle Area矩形面积
/* 像是一道数据分析题 思路就是两个矩形面积之和减去叠加面积之和 */ public int computeArea(int A, int B, int C, int D, int E, int F ...
- 【刷题-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, ...
- 【一天一道LeetCode】#223. Rectangle Area
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Find th ...
随机推荐
- String的compareTo()方法返回值
compareTo()的返回值是整型,它是先比较对应字符的大小(ASCII码顺序),如果第一个字符和参数的第一个字符不等,结束比较,返回他们之间的 差值,如果第一个字符和参数的第一个字符相等,则以第二 ...
- linux 下 nginx 启动服务器 80端口被占用问题
把80端口占用的程序杀死 sudo fuser -k 80/tcp rm -fr 文件 ----删除文件及文加下的所有文件 echo > filename ---清空文件的内容
- (五)Linux引导流程解析
目录 Linux引导流程 Linux运行级别 Linux启动服务管理 GRUB配置与应用 启动故障分析与解决 Linux引导流程 Linux系统引导流程如下图: 固件(Firmware)就是写入ERO ...
- 支付宝客户端支付配置RSA公钥的问题错误,导致收不到回发通知
没收到通知的原因是你们的商户公钥上传地址弄错了,应该上传到合作伙伴管理,您上传到无线wap哪里了,把您的公钥,从无线wap哪里复制贴到合作伙伴管理即可
- [Hibernate] - mysql
Hibernate使用mysql例子: 1) 新建一个bean: User.java package com.my.bean; import java.util.Date; public class ...
- .net平台的RSA实现以及与Delphi之间的互操作性
.net平台下面的RSA算法实现是RSACryptoServiceProvider,如果安装了 Microsoft Enhanced Cryptographic Provider,则 RSACrypt ...
- [转]使用 Minidumps 和 Visual Studio .NET 进行崩溃后调试
本文关键字:Minidumps, Windows, SEH, VisualC, .NET 摘要 本文讲述了 minidumps 是怎样工作的.当你的程序崩溃的时候应该如何生成它们.以及如何在 Visu ...
- JS使用百度地图API
尚未整理: <script type="text/javascript"> var map = new BMap.Map("dituContent" ...
- Redis报错:WRONGTYPE Operation against a key holding the wrong kind of value 解决处理
首先应该明白报这个错误说明了你用的jedis方法与redis服务器中存储数据的类型存在冲突. 例如:数据库中有一个key的数据存储的是Hash类型的,但是你使用jedis执行数据操作的时候却使用了非H ...
- Env:VIM配置
注:文章来自于http://www.cnblogs.com/ma6174/archive/2011/12/10/2283393.html 花了很长时间整理的,感觉用起来很方便,共享一下. 我的vim配 ...