LeetCode 223. 矩形面积(Rectangle Area)
223. 矩形面积
223. Rectangle Area
题目描述
在二维平面上计算出两个由直线构成的矩形重叠后形成的总面积。
每个矩形由其左下顶点和右上顶点坐标表示,如图所示。

LeetCode223. Rectangle Area中等
示例:
输出: 45
说明: 假设矩形面积不会超出 int 的范围。
Java 实现
class Solution {
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int area1 = (C - A) * (D - B), area2 = (G - E) * (H - F);
int left = Math.max(A, E);
int right = Math.min(C, G);
int bottom = Math.max(B, F);
int top = Math.min(D, H);
int overlap = 0;
if (right > left && top > bottom) {
overlap = (right - left) * (top - bottom);
}
return area1 + area2 - overlap;
}
}
相似题目
参考资料
LeetCode 223. 矩形面积(Rectangle Area)的更多相关文章
- Java实现 LeetCode 223 矩形面积
223. 矩形面积 在二维平面上计算出两个由直线构成的矩形重叠后形成的总面积. 每个矩形由其左下顶点和右上顶点坐标表示,如图所示. Rectangle Area 示例: 输入: -3, 0, 3, 4 ...
- [Swift]LeetCode223. 矩形面积 | Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...
- [LeetCode] 223.矩形面积
题目链接: https://leetcode-cn.com/problems/rectangle-area 难度:中等 通过率:41.3% 题目描述: 在 二维 平面上计算出两个 由直线构成的 矩形重 ...
- LeetCode之“数学”:Rectangle Area
题目链接 题目要求: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle i ...
- 【leetcode】Contains Duplicate & Rectangle Area(easy)
Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your funct ...
- 【一天一道LeetCode】#85. Maximal Rectangle
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- [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 ...
随机推荐
- java项目部署
本文章只为帮助大家学习项目的发布,为基础篇,在此给大家示范在window环境下的项目部署及运维. 以下版本为讲解示例,可自行改至匹配版本. 服务器:window service2008 R2 Stan ...
- 【游记】CSP2019 垫底记
考试时候的我: Day 1 做完 \(T1\) 和 \(T2\),还有 \(2.5 h\),我想阿克 \(Day1\).(\(T3\):不,你不想) 不过一会就想出来给每个点 dfs 贪心选一个点,然 ...
- hdu4767 Bell——求第n项贝尔数
题意 设第 $n$ 个Bell数为 $B_n$,求 $B_n \ mod \ 95041567$.($1 \leq n \leq 2^{31}$) 分析 贝尔数的概念和性质,维基百科上有,这里 ...
- yii2 oracle 原生sql分页
$sql_list = "SELECT ID, FID, INSID, FLIGHTNO, DEPNAME, ARRNAME, to_char(DEPDATE,'yyyy-MM-dd HH2 ...
- git:GitLab代码回滚到特定版本
在当前branch上多次commit代码并且push后,发现不符合要求,需要回滚到特定的版本.步骤如下: 1.查找commitId (1)用命令行打开git项目路径,输入git log命令查看comm ...
- ES6 数组方法 forEach map filter find every some reduce
1. forEach const colors = ['red', 'blue', 'green'] colors.forEach(function (params) { console.log(pa ...
- 第10组alpha冲刺(2/4)
队名:凹凸曼 组长博客 作业博客 组员实践情况 童景霖 过去两天完成了哪些任务 文字/口头描述 继续学习Android studio和Java 完善项目APP原型 展示GitHub当日代码/文档签入记 ...
- Eclipse R语言开发环境搭建 StatET插件
StatET 官网 http://www.walware.de/goto/statet Installation 点击菜单栏 help --> Install New Software 配置R语 ...
- GIT 安装和升级
git 安装: http://git-scm.com/download/mac git 升级: $ git clone git://git.kernel.org/pub/scm/git/git.git
- locust参数化(数据库取值)
locust参数化(数据库取值) 基于上一篇参数化的梳理,本篇用另一种方法从数据库中取出这100个用户来登录 思路:在 TaskSet 中的 on_start 方法表示执行任务前的操作,可以将数据库取 ...