223 Rectangle Area 矩形面积
在二维平面上计算出两个由直线构成的矩形叠加覆盖后的面积。
假设面积不会超出int的范围。
详见:https://leetcode.com/problems/rectangle-area/description/
Java实现:
- class Solution {
- public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
- int sum = (C - A) * (D - B) + (H - F) * (G - E);
- if (E >= C || F >= D || B >= H || A >= G){
- return sum;
- }
- return sum - ((Math.min(G, C) - Math.max(A, E)) * (Math.min(D, H) - Math.max(B, F)));
- }
- }
C++实现:
- class Solution {
- public:
- int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
- int sum = (C - A) * (D - B) + (H - F) * (G - E);
- if (E >= C || F >= D || B >= H || A >= G)
- {
- return sum;
- }
- return sum - ((min(G, C) - max(A, E)) * (min(D, H) - max(B, F)));
- }
- };
参考:https://www.cnblogs.com/grandyang/p/4563153.html
223 Rectangle Area 矩形面积的更多相关文章
- [LeetCode] 223. Rectangle Area 矩形面积
Find the total area covered by two rectilinearrectangles in a 2D plane. Each rectangle is defined by ...
- [LeetCode]223. Rectangle Area矩形面积
/* 像是一道数据分析题 思路就是两个矩形面积之和减去叠加面积之和 */ public int computeArea(int A, int B, int C, int D, int E, int F ...
- [LeetCode] Rectangle Area 矩形面积
Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...
- (easy)LeetCode 223.Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...
- 【刷题-LeetCode】223. Rectangle Area
Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...
- [HDU 4419] Colourful Rectangle (扫描线 矩形面积并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4419 题目大意:比矩形面积并多了颜色,问染成的每种颜色的面积. 矩形面积并的扫描线维护的是长度,这道题 ...
- LeetCode 223 Rectangle Area(矩形面积)
翻译 找到在二维平面中两个相交矩形的总面积. 每一个矩形都定义了其左下角和右上角的坐标. (矩形例如以下图) 如果,总占地面积永远不会超过int的最大值. 原文 分析 这题前天试过,写了一堆推断.终究 ...
- 223. Rectangle Area
题目: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defin ...
- LeetCode OJ 223.Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...
随机推荐
- Visual Studio VS如何拷贝一个项目的窗体文件到另一个项目
1 比如下我有一个项目,我要把这个Config整个窗体和代码拷贝到另一个项目 2 在新项目中添加现有项,然后把这个窗体相关的三个文件都添加到新的项目中 3 然后在新窗体中就什么都有了 ...
- Linux程序设计(搭建开发环境--curses)
看官们.咱们今天要说的内容.是前面内容的一点小补充,详细的内容是:安装curses开发包.以搭建 开发环境.闲话休说,言归正转. 我们在前面说过搭建开发环境的内容,主要说了开发环境中的GCC和VIM, ...
- Android 性能优化探究
使用ViewStub动态载入布局.避免一些不常常的视图长期握住引用: ViewStub的一些特点: 1. ViewStub仅仅能Inflate一次,之后ViewStub对象被置空:某个被ViewStu ...
- OpenCV入门笔记(二) 图片的文件操作
以下介绍一下重要的几个,设计基本 图片处理 的函数,依次来了解OpenCV的入门知识.具体的具体使用方法还是以官方的API[Official Tutorials][Python-OpenCV]为准. ...
- 【iOS-Tips】-小贴士
[iOS-Tips]-小贴士 1:UIImage的2种加载方式: 方式一:有缓存(图片所占用的内存会一直停留在程序中) //name是图片的文件名 + (UIImage *)imageNamed:(N ...
- ufldl学习笔记与编程作业:Logistic Regression(逻辑回归)
ufldl学习笔记与编程作业:Logistic Regression(逻辑回归) ufldl出了新教程,感觉比之前的好,从基础讲起.系统清晰,又有编程实践. 在deep learning高质量群里面听 ...
- IP达人启示录(学会经营自己:靠软件来扩大自己的IP,或者获取很大的名声)
在家附近的一个小公园中,一个老人每天晚上都在用水练习书法,他的字写的的确很不错,不懂书法的我,看了就感觉非常的带劲--苍劲有力.今晚再次路过的时候,就有种想和这个老人聊一聊的冲动,那么多年纪了,用书法 ...
- ELF和a.out文件格式的比较
本文讨论了 UNIX/LINUX 平台下三种主要的可执行文件格式:a.out(assembler and link editor output 汇编器和链接编辑器的输出).COFF(Common Ob ...
- kafka-net
基于kafka-net实现的可以长链接的消息生产者 今天有点时间,我就来说两句.最近接触的Kafka相关的东西要多一些,其实以前也接触过,但是在项目使用中的经验不是很多.最近公司的项目里面使用了Kaf ...
- 常用的 Nand Flash 指令如下:
指令 功能 nand info 显示可使用的 Nand Flash nand device [dev] 显示或设定当前使用的 Nand Flash nand read addr off size ...