(easy)LeetCode 223.Rectangle Area
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.
解法:两个矩形面积相加,有重叠部分,则减去重叠部分。重叠部分面积计算。左点的最大值,与右点的最小,比较
代码如下:
public class Solution {
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int res=(C-A)*(D-B)+(G-E)*(H-F);
int A1=Math.max(A,E);
int B1=Math.max(B,F);
int C1=Math.min(C,G);
int D1=Math.min(D,H);
if(A1>=C1 || B1>=D1) return res;
return res-(C1-A1)*(D1-B1);
}
}
运行结果:

(easy)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 ...
- 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 223 Rectangle Area(矩形面积)
翻译 找到在二维平面中两个相交矩形的总面积. 每一个矩形都定义了其左下角和右上角的坐标. (矩形例如以下图) 如果,总占地面积永远不会超过int的最大值. 原文 分析 这题前天试过,写了一堆推断.终究 ...
- [LeetCode]223. Rectangle Area矩形面积
/* 像是一道数据分析题 思路就是两个矩形面积之和减去叠加面积之和 */ public int computeArea(int A, int B, int C, int D, int E, int F ...
- 【刷题-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, ...
- 【一天一道LeetCode】#223. Rectangle Area
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Find th ...
随机推荐
- python简单粗暴多进程之concurrent.futures
python在前面写过多线程的库threading: python3多线程趣味详解 但是今天发现一个封装得更加简单暴力的多进程库concurrent.futures: # !/usr/bin/pyth ...
- ios 获取屏幕的属性和宽度
app尺寸,去掉状态栏 CGRect r = [ UIScreen mainScreen ].applicationFrame; r=0,20,320,460 屏幕尺寸 CGRect rx = [ U ...
- 取消GridView/ListView item被点击时的效果
方法一,在控件被初始化的时候设置 ? 1 2 gridView.setSelector(new ColorDrawable(Color.TRANSPARENT)); listView.setSelec ...
- firefox不支持background-position-x background-position-y,使用background-position:5px 5px;
firefox不支持background-position-x background-position-y,使用background-position:5px 5px;
- mongodb 最佳实践
MongoDB功能预览:http://pan.baidu.com/s/1k2UfW MongoDB在赶集网的应用:http://pan.baidu.com/s/1bngxgLp MongoDB在京东的 ...
- MyBatis插入多条
<insert id="insertProjectPropertyRelList" parameterType="java.util.List"> ...
- AngularJs初步学习笔记(part1)
一.摘要: angular是采用JavaScript编写的前端mvc框架,帮助开发者编写现代化的单页面应用.它尤其适用编写有大量CRUD操作的,具有Ajax风格的客户端应用. 二.总结: Angula ...
- log4net 部署到服务器之后 无法记录日志问题 解决方法
通常情况下无法记录日志的原因是:权限问题 1. 右键该站点的程序文件夹>>安全 2. 找到 IIS_IUSR 用户,然后编辑权限 允许修改,保存即可 3. 搞定
- webform 页面传值的方法总结
ASP.NET页面之间传递值的几种方式 页面传值是学习asp.net初期都会面临的一个问题,总的来说有页面传值.存储对象传值.ajax.类.model.表单等.但是一般来说,常用的较简单有Quer ...
- linq简介
语言集成查询(Language INtegrated Query,LINQ)是一项微软技术,新增一种自然查询的SQL语法到.NET Framework的编程语言中,可支持Visual Basic .N ...