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 ...
随机推荐
- postgresql 导入 导出(一张表)
导入sql -w 指定数据库名 psql -h 192.168.20.123 -p 5432 -w warehouse < /usr/20180808.sql 导出一张表sql -w ...
- Build Post Office
Description Given a 2D grid, each cell is either an house 1 or empty 0 (the number zero, one), find ...
- Tensorflow细节-P309-高维向量可视化
import matplotlib.pyplot as plt import tensorflow as tf import numpy as np import os from tensorflow ...
- 2019.12.09 java循环(do……while)
class Demo05{ public static void main(String[] args) { int sum=0; int i=1; do{ sum+=i; i++; }while(i ...
- WinDbg常用命令系列---断点操作b*
ba (Break on Access) ba命令设置处理器断点(通常称为数据断点,不太准确).此断点在访问指定内存时触发. 用户模式下 [~Thread] ba[ID] Access Size [O ...
- vlang module 使用
vlang 支持module,概念以及使用类似rust 以及golang 的gopath(从当前的文档以及使用来说),但是还不完整 以及是够用,但是有问题 v module 试用 项目结构 ├── ...
- 机器学习---三种线性算法的比较(线性回归,感知机,逻辑回归)(Machine Learning Linear Regression Perceptron Logistic Regression Comparison)
最小二乘线性回归,感知机,逻辑回归的比较: 最小二乘线性回归 Least Squares Linear Regression 感知机 Perceptron 二分类逻辑回归 Binary Logis ...
- 2016android在线测试15-图像 camera2
1.ImageView类用于显示各种图像,例如:图标,图片,下面对于ImageView类加载图片方法的描述有: void setImageResource(int resld): 设置Drawanbl ...
- 第09组 团队Git现场编程实战
组长博客链接 1.团队分工 团队成员 分工明细 王耀鑫 博客撰写,数据处理 陈志荣 前端界面,前端功能实现 陈超颖 前端界面,前端功能实现 沈梓耀 前端界面,前端功能实现 林明镇 数据处理 滕佳 前端 ...
- mysql distinct()函数 去重
mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | t ...