【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.
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的更多相关文章
- 【LeetCode】223. Rectangle Area 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/rectangl ...
- 【刷题-LeetCode】223. Rectangle Area
Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...
- 【一天一道LeetCode】#223. Rectangle Area
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Find th ...
- 【leetcode】963. Minimum Area Rectangle II
题目如下: Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from ...
- 【LeetCode】836. Rectangle Overlap 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/rectangle ...
- 【leetcode❤python】 223. Rectangle Area
#-*- coding: UTF-8 -*-#先判断是否有重叠class Solution(object): def computeArea(self, A, B, C, D, E, F, G, ...
- 【LeetCode】963. Minimum Area Rectangle II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 线段长+线段中心+字典 日期 题目地址:https: ...
- 【LeetCode】939. Minimum Area Rectangle 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 确定对角线,找另外两点(4sum) 字典保存出现的x ...
- 【leetcode】939. Minimum Area Rectangle
题目如下: Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from t ...
随机推荐
- Java实现cache的基本机制
我这里说的cache不是指CPU和RAM之间的缓存,而是Java应用中间常用的缓存.最常使用的场合就是访问数据库的时候为了提高效率而使用的 cache.一般的用法就是把数据从数据库读到内存,然后之后的 ...
- Spring_MVC_教程_快速入门_深入分析
Spring MVC 教程,快速入门,深入分析 博客分类: SPRING Spring MVC 教程快速入门 资源下载: Spring_MVC_教程_快速入门_深入分析V1.1.pdf Spring ...
- 《MySQL悲观锁总结和实践》乐观锁
mysql乐观锁总结和实践 博客分类: MyBatis 数据库 mysql数据库乐观锁悲观锁 上一篇文章<MySQL悲观锁总结和实践>谈到了MySQL悲观锁,但是悲观锁并不是适用于任何场景 ...
- SQL SERVER ->> Wait Stats
等待状态是隔离SQL SERVER性能问题的一个重要手段,从实例级别入手.可以大概看出SQL SERVER在过去某段时间内是否处于某种资源的吃紧状态.不过取决于你是否有建立有效的性能数据收集机制.sy ...
- 机器人学 —— 轨迹规划(Configuration Space)
之前的轨迹规划中,我们只考虑了质点,没有考虑机器人的外形与结构.直接在obstacle map 中进行轨迹规划,然而世纪情况中,机器人有固定外形,可能会和障碍物发生碰撞.此情况下,我们针对机器人自由度 ...
- PHP 对象和数组互相转换
最简单的:$array = (array)$object; 但是, 如果对象的属性也是个对象的话, 就转换不了了, 就是说PHP的强制类型转换不能把对象属性中的对象转换成数组的下一个维度的数组, 刚刚 ...
- 原生javascript-常用的函数
[一]添加监听事件 addHandler:function(node,type,fn){if(node.addEventListener){ node.addEventListener(type,fn ...
- Windows Myeclipse 10 安装 Perl 插件
1.首先安装 windows 下的 perl 环境这里使用 active perl,选择最新版本 5.16.1下载地址:http://www.activestate.com/activeperl/do ...
- Linux 总结1
============================= 一般 ========================================= chown -R oracle:oinstall ...
- 纠结和郁闷的存在感-关于DirectX与HLSL的矩阵存储方式---转载好文章
我常常这么大胆的认为,搞科学的人总是喜欢用各种让常人难以理解的复杂方式去处理某些其实可能很简单的事情,这种情况在他自身擅长的.有着诸多对手竞争的领域上极为常见.比如吧,搞DirectX的人用了左手坐标 ...