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.

Solution: 两长方形面积之和减去重合部分面积;当A>=G或C<=E或B>=H或D<=F时,两长方形不相交;

 class Solution {
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int width,height;
if(A>=G||C<=E||B>=H||D<=F){
width=;
height=;
}else{
if(A<=E)
width=min(C-E,G-E);
else
width=min(C-A,G-A); if(B<=F)
height=min(D-F,H-F);
else
height=min(D-B,H-B);
}
return (C-A)*(D-B)+(G-E)*(H-F)-height*width;
}
};

【LeetCode】223 - Rectangle Area的更多相关文章

  1. 【LeetCode】223. Rectangle Area 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/rectangl ...

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

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

  3. 【一天一道LeetCode】#223. Rectangle Area

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Find th ...

  4. 【leetcode】963. Minimum Area Rectangle II

    题目如下: Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from ...

  5. 【LeetCode】836. Rectangle Overlap 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/rectangle ...

  6. 【leetcode❤python】 223. Rectangle Area

    #-*- coding: UTF-8 -*-#先判断是否有重叠class Solution(object):    def computeArea(self, A, B, C, D, E, F, G, ...

  7. 【LeetCode】963. Minimum Area Rectangle II 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 线段长+线段中心+字典 日期 题目地址:https: ...

  8. 【LeetCode】939. Minimum Area Rectangle 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 确定对角线,找另外两点(4sum) 字典保存出现的x ...

  9. 【leetcode】939. Minimum Area Rectangle

    题目如下: Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from t ...

随机推荐

  1. struts使用html:file上传文件的时候文件名乱码解决

    <body> <html:form action="/jwid/struts1x/15.3/form/upload.do?action=upload" encty ...

  2. OpenGL环境搭建Windows+Mac+Linux

    OpenGL环境搭建Windows+Mac+Linux Mac平台下 下载列表:GLFWcmake 下载的GLFW解压缩 然后安装cmake, 安装好cmake之后打开 1.browse source ...

  3. Android处理Bitmap的一些方法

    http://www.it165.net/pro/html/201305/5795.html # 文件与Bitmap间的方法 1. 从文件载入Bitmap 01./** 02.* @brief 从文件 ...

  4. hihoCoder 1051补提交卡(贪心 枚举)

    http://hihocoder.com/problemset/problem/1051 既然要选择最长连续提交天数,那么提交卡必须连续使用才有可能得到最优解,这样贪心,然后从头到尾扫一遍求出最大值. ...

  5. Android内存管理(1)WRANGLING DALVIK: MEMORY MANAGEMENT IN ANDROID PART 1

    from : http://www.raizlabs.com/dev/2014/03/wrangling-dalvik-memory-management-in-android-part-1-of-2 ...

  6. BZOJ 1452 Count(二维树状数组)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1452 题意:给出一个数字矩阵(矩阵中任何时候的数字均为[1,100]),两种操作:(1) ...

  7. leetcode:Multiply Strings

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  8. Using dblink in Postgres

    select contractid from tcim_s_enterprice EXCEPT select contractid from dblink ( 'host=172.16.51.25 p ...

  9. JavaScript高级编程(一)

    书中第2章,在HTML中使用JavaScript摘要总结 2.1 <script>元素 <script>中的5个属性:charset:可选.表示通过src属性指定的代码的字符集 ...

  10. JSON 之 SuperObject(3): 访问

    测试数据提前加入 Memo1 中: 代码文件: unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, ...