【一天一道LeetCode】#223. Rectangle Area
一天一道LeetCode
本系列文章已全部上传至我的github,地址:ZeeCoder‘s Github
欢迎大家关注我的新浪微博,我的新浪微博
欢迎转载,转载请注明出处
(一)题目
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.
(二)解题
题目大意:求两个矩形总的覆盖面积。
解题思路:判断两个数组不重叠,满足C<=E||G<=A||F>=D||B>=H,
如果重叠求重叠面积:(min(C,G)-max(A,E))*(min(D,H)-max(B,F))。
下面是代码:
class Solution {
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int total = (C-A)*(D-B)+(G-E)*(H-F);
if(C<=E||G<=A||F>=D||B>=H) return total;//不重叠
return total - (min(C,G)-max(A,E))*(min(D,H)-max(B,F));//重叠
}
};
【一天一道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 ...
- (easy)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矩形面积
/* 像是一道数据分析题 思路就是两个矩形面积之和减去叠加面积之和 */ public int computeArea(int A, int B, int C, int D, int E, int F ...
- LeetCode : 223. Rectangle Area
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABRQAAAQ0CAYAAAAPPZBqAAAMFGlDQ1BJQ0MgUHJvZmlsZQAASImVlw
- LeetCode 223 Rectangle Area(矩形面积)
翻译 找到在二维平面中两个相交矩形的总面积. 每一个矩形都定义了其左下角和右上角的坐标. (矩形例如以下图) 如果,总占地面积永远不会超过int的最大值. 原文 分析 这题前天试过,写了一堆推断.终究 ...
- 【刷题-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, ...
随机推荐
- poj2449 (第k条最短路)
题意:求n个点中,a到b的第k条最短路 思路: 用最短路求出估价函数的h,再在搜索过程中记录g,利用A*求出 最开始想到的便是A*和最短路,但是脑子抽了,居然一个一个去求- -,TL了后才发现可以倒着 ...
- 智能优化算法对TSP问题的求解研究
要求: TSP 算法(Traveling Salesman Problem)是指给定 n 个城市和各个城市之间的距离,要 求确定一条经过各个城市当且仅当一次的最短路径,它是一种典型的优化组合问题,其最 ...
- (概念)多个CPU和多核CPU以及超线程(Hyper-Threading)
引言 在这篇文章中我会主要介绍CPU相关的一些重要概念和技术.如果你想更好地了解操作系统,那就从本文开始吧. 中央处理器(Central processing unit) 在我们了解其它概念之前,我们 ...
- 修改hosts不必重启 立刻生效
打开命令提示符窗口执行以下命令: 显示DNS缓存内容 ipconfig /displaydns 删除DNS缓存内容 ipconfig /flushdns ps.电脑卡的话,先关机再开机(别直接重启)
- 开源Spring解决方案--lm.solution
Github 项目地址: https://github.com/liumeng0403/lm.solution 一.说明 1.本项目未按java项目传统命名方式命名项目名,包名 如:org.xxxx. ...
- Java不走弯路教程(1.环境搭建)
1.环境搭建在开始写第一个Java程序之前,我们需要做一些简单的准备工作. 1.1 还记得DOS吗 我们可以通过图形界面来操作我们的电脑.但作为程序员,你首先需要学会用命令行的方式来操作电脑,因为不是 ...
- spring的事务配置方法
spring事务的配置有两种方式 1.xml配置的声明式事务配置 (1)配置数据源信息dataSource(使用阿里的数据源) <bean id="dataSource" c ...
- python3.6 使用 pymysql 连接 Mysql 数据库及 简单的增删改查操作
1.通过 pip 安装 pymysql 进入 cmd 输入 pip install pymysql 回车等待安装完成: 安装完成后出现如图相关信息,表示安装成功. 2.测试连接 import ...
- mysql5.7在centos上安装的完整教程以及相关的“坑”
安装前的准备 Step1: 如果你系统已经有mysql,如一般centos自带mysql5.1系列,那么你需要删除它,先检查一下系统是否自带mysql yum list installed | gre ...
- python语言学习
前段时间要做视频直播需要编写自动模块,就考虑使用python脚本语言,python的好多语法都是很独特的,比如数据类型不需要预定义,缩进的方式等,另外功能也很强大,豆瓣就是用python写的.我写的部 ...