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.

Credits:
Special thanks to @mithmatt for adding this problem, creating the above image and all test cases.

解题思路:

JAVA实现如下:

    public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int minu=0;
if(E>=C||G<=A||F>=D||H<=B)
minu=0;
else minu=(Math.min(G,C)-Math.max(A,E))*(Math.min(D, H)-Math.max(F, B));
return (C-A)*(D-B)+(G-E)*(H-F)-minu;
}

Java for LeetCode 223 Rectangle Area的更多相关文章

  1. [LeetCode] 223. Rectangle Area 矩形面积

    Find the total area covered by two rectilinearrectangles in a 2D plane. Each rectangle is defined by ...

  2. Java [Leetcode 223]Rectangle Area

    题目描述: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is def ...

  3. (easy)LeetCode 223.Rectangle Area

    Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...

  4. LeetCode : 223. Rectangle Area

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABRQAAAQ0CAYAAAAPPZBqAAAMFGlDQ1BJQ0MgUHJvZmlsZQAASImVlw

  5. LeetCode 223 Rectangle Area(矩形面积)

    翻译 找到在二维平面中两个相交矩形的总面积. 每一个矩形都定义了其左下角和右上角的坐标. (矩形例如以下图) 如果,总占地面积永远不会超过int的最大值. 原文 分析 这题前天试过,写了一堆推断.终究 ...

  6. [LeetCode]223. Rectangle Area矩形面积

    /* 像是一道数据分析题 思路就是两个矩形面积之和减去叠加面积之和 */ public int computeArea(int A, int B, int C, int D, int E, int F ...

  7. 【刷题-LeetCode】223. Rectangle Area

    Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...

  8. [LeetCode] 850. Rectangle Area II 矩形面积之二

    We are given a list of (axis-aligned) rectangles.  Each rectangle[i] = [x1, y1, x2, y2] , where (x1, ...

  9. Java实现 LeetCode 223 矩形面积

    223. 矩形面积 在二维平面上计算出两个由直线构成的矩形重叠后形成的总面积. 每个矩形由其左下顶点和右上顶点坐标表示,如图所示. Rectangle Area 示例: 输入: -3, 0, 3, 4 ...

随机推荐

  1. 弹出框四 之toastr.js (完成提示框)

    1.下载 toastr.js组件 2. $(function () { toastr.success('提交数据成功'); toastr.error('Error'); toastr.warning( ...

  2. unzip 命令使用

    http://blog.sina.com.cn/s/blog_6c9d65a10100nzqf.html unzip命令:解压缩文件 他是解压zip压缩的文件,和zip互逆的一对工具.   命令: u ...

  3. CSS文档流

    文档流 将窗体自上而下分成一行行, 并在每行中按从左至右的顺序排放元素,即为文档流. 每个非浮动块级元素都独占一行, 浮动元素则按规定浮在行的一端. 若当前行容不下, 则另起新行再浮动. 内联元素也不 ...

  4. word中替换被批注的正文的值

    word中替换被批注的正文的值   word批注winform替换值正文             try            {                Word.Document docum ...

  5. Linux中postfix邮件服务器的搭建

    postfix是Wietse Venema在IBM的GPL协议之下开发的MTA(邮件传输代理)软件.postfix是Wietse Venema想要为使用最广泛的sendmail提供替代品的一个尝试.在 ...

  6. iOS之下拉放大,上推缩小,一个方法搞定

    先来看看效果吧. 讲讲大概的实现思路:1、创建头部的视图和tableview,需要注意的是tableview要设置contentInset,contentInsent 的顶部要和头部视图的背景图的高度 ...

  7. cocos2d-x内存管理(见解)

    cocos2d-x 延续了cocos2d 和OC的引用计数的内存管理机制! 下面我们来看看CCDriectro类 CCPoolManager::sharedPoolManager()->push ...

  8. javascript小技巧(非常全)

    事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture();  event.srcE ...

  9. python 环境安装

    wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz  tar zxf Python-2.7.3.tgz  cd Python-2. ...

  10. php服务端写日志文件

    1.需求 在服务端记录日志 2.基础版 最基础的文件读写,(要注意window和linux的换行符,window是\r\n,linux是\n),这里就写入一个时间. <?php $handle ...