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. Promise 异步(asynchronous )编程

    概述 Promise.all(iterable) 方法返回一个promise,该promise会等iterable参数内的所有promise都被resolve后被resolve,或以第一个promis ...

  2. 如何解压.bz2文件包

    .bz2  解压1:bzip2 -d FileName.bz2  解压2:bunzip2 FileName.bz2  压缩: bzip2 -z FileName  .tar.bz2  解压:tar j ...

  3. golang笔记——IDE

    可选方案有 Lite IDE\GoSublime\Visual Studio Code\Goclipse\Vim 1.Lite IDE 这是国人开发的开源且跨平台的 golang 专属IDE,也算是目 ...

  4. [转载]JavaScript内存分析

    https://github.com/CN-Chrome-DevTools/CN-Chrome-DevTools/blob/master/md/Performance-Profiling/javasc ...

  5. ZOJ 3201 Tree of Tree

    树形DP.... Tree of Tree Time Limit: 1 Second      Memory Limit: 32768 KB You're given a tree with weig ...

  6. Android学习笔记函数

    //调用新的Activity Intent intent=new Intent(MainActivity.this,Main2Activity.class); startActivity(intent ...

  7. int (*p)[4] 与 int* p[4]

    碰到一道题: ][] = {,,,,,,,,,,,}; ]; ] = (a+); cout<<*(p+)<<endl; cout<<(*ptr+)[]<< ...

  8. css3常用标签

    30个最常用css选择器解析   你也许已经掌握了id.class.后台选择器这些基本的css选择器.但这远远不是css的全部.下面向大家系统的解析css中30个最常用的选择器,包括我们最头痛的浏览器 ...

  9. 理解js中this的指向

         学习自原文  http://www.cnblogs.com/pssp/p/5216085.html后的一点小结(原文作者总结的很棒^_^)! 关于js中this的指向,在函数定义的时候还无法 ...

  10. 导航栏的坑 (导航透明/导航除线/titleIView)

    //以下四个条件缺一不可 /.必须是半透明状态 self.navigationBar.translucent = YES; //2.导航栏背景图片为空图片 (不可以设置backgroundColor或 ...