[LeetCode]223. Rectangle Area矩形面积
/*
像是一道数据分析题
思路就是两个矩形面积之和减去叠加面积之和
*/
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
//求两个面积
int a1 = (C-A)*(D-B);
int a2 = (G-E)*(H-F);
//求叠加面积,(低上限-高下限)*(左右线-右左线)
int h1 = Math.min(D,H);
int h2 = Math.max(B,F);
int w1 = Math.min(C,G);
int w2 = Math.max(E,A);
//这里要考虑到没有相交的情况
//同时这里不能比较h1-h2和0的大小,因为如果负数太大会溢出,比0大
int o = (h1<=h2||w1<=w2)?0:(h1-h2)*(w1-w2);
return a1+a2-o;
}
[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 ...
- 223 Rectangle Area 矩形面积
在二维平面上计算出两个由直线构成的矩形叠加覆盖后的面积. 假设面积不会超出int的范围. 详见:https://leetcode.com/problems/rectangle-area/descrip ...
- [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(矩形面积)
翻译 找到在二维平面中两个相交矩形的总面积. 每一个矩形都定义了其左下角和右上角的坐标. (矩形例如以下图) 如果,总占地面积永远不会超过int的最大值. 原文 分析 这题前天试过,写了一堆推断.终究 ...
- Java for 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
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABRQAAAQ0CAYAAAAPPZBqAAAMFGlDQ1BJQ0MgUHJvZmlsZQAASImVlw
- [LeetCode] 850. Rectangle Area II 矩形面积之二
We are given a list of (axis-aligned) rectangles. Each rectangle[i] = [x1, y1, x2, y2] , where (x1, ...
随机推荐
- 14_TTS
TTS(Text to speech)为语音合成的意思.本课程主要介绍了TTS的使用方法. 1 package cn.eoe.tts; 2 3 import java.util.Locale; 4 i ...
- 【佛山市选2013】JZOJ2020年8月7日提高组T3 海明距离
[佛山市选2013]JZOJ2020年8月7日提高组T3 海明距离 题目 描述 对于二进制串a,b,他们之间的海明距离是指两个串异或之后串中1的个数.异或的规则为: 0 XOR 0 = 0 1 XOR ...
- 数据库:Flask-SQLAlchemy
一.安装以及使用 1.安装 安装 flask-sqlalchemy pip install flask-sqlalchemy 如果连接的是 mysql 数据库,需要安装 mysqldb pip ins ...
- 第2.3节 Python运算符大全
一. Python的算术运算 Python的算术运算符与C语言类似,略有不同.包括加(+).减(-).乘(*).除(/).取余(%).按位或(|).按位与(&).按位求补(~).左移位(< ...
- moviepy音视频剪辑VideoClip类fl_image方法及参数image_func的功能介绍
☞ ░ 前往老猿Python博文目录 ░ moviepy音视频剪辑模块的视频剪辑基类VideoClip的fl_image方法用于进行对剪辑帧数据进行变换. 调用语法:fl_image(self, im ...
- Python中的"缝合器"zip函数:将多个可迭代对象组合成一个迭代器
zip函数将参数中多个可迭代对象中相同序号的元素取出组合成一个元组作为输出列表的一个同样序号的元素,即输出列表的每个元素是一个元组,该元组的元素来源于参数中每个迭代对象的对应序号的元素. 具体可参考: ...
- TCP连接时动态端口的相关问题说明
最近在线上遇到一个TCP动态端口相关的问题,之前没有留意过此类问题,做个笔记记录在这里,希望也能给大家提供个参考. 简单介绍下问题的场景:Windows服务器上,部署了网关程序SG和RPC进程,其中R ...
- sql注入之union注入
联合查询注入利用的前提: 必须要有回显 联合查询过程: 判断是否存在注入点 判断是什么类型注入(字符型or数字型) 判断闭合方式 查询列数个数(order by) 5, 获得数据库名 获得表名 获得字 ...
- Azure应用服务+Github实现持续部署
上次我们介绍了如何使用Azure应用服务(不用虚机不用Docker使用Azure应用服务部署ASP.NET Core程序).我们通过Visual studio新建一个项目后手动编译发布代码.然后通过F ...
- github拉去代码慢的处理方式(最简单)
https://github.com/xxx/xxxx 替换成 https://github.com.cnpmjs.org/xxx/xxxx 再去拉取,速度快很多,亲测可用