Java [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 areaOfA = (C - A) * (D - B);
int areaOfB = (G - E) * (H - F);
int left = Math.max(A, E);
int right = Math.min(C, G);
int top = Math.min(D, H);
int bottom = Math.max(B, F);
int overlap = 0;
if(right > left && top > bottom)
overlap = (right - left) * (top - bottom);
return areaOfA + areaOfB - overlap;
}
}
Java [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 ...
- (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
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 ...
随机推荐
- 剑指offer--面试题14
#include "stdafx.h" #include <iostream> using namespace std; //调整数组顺序使奇数位于偶数前 void O ...
- sampler2d
Here is the syntax for a sampler in Direct3D 9. sampler Name = SamplerType{ Texture = <texture_ ...
- Sqrt函数高效实现
转自一个Sqrt函数引发的血案 我们平时经常会有一些数据运算的操作,需要调用sqrt,exp,abs等函数,那么时候你有没有想过:这个些函数系统是如何实现的?就拿最常用的sqrt函数来说吧,系统怎么来 ...
- 中国移动MM Android/OPhone付费SDK--MMBillingSDK,集成问题总结
原地址:http://www.j2megame.com/html/xwzx/ty/2916.html 中国移动MM Android/OPhone付费SDK--MMBillingSDK,集成问题总结 近 ...
- [unity3d]手游资源热更新策略探讨
原地址:http://blog.csdn.net/dingxiaowei2013/article/details/20079683 我们学习了如何将资源进行打包.这次就可以用上场了,我们来探讨一下手游 ...
- css table表格无法调整宽度问题分析
1.在网上查找了相关问题,有的说表格设置了背景图片,把原来的宽度撑开了,导致无法变窄~! 在项目中,原来美工设计的页面,设置了一个块的样式class="title",现在有一段ht ...
- PHP字符串函数之 strstr stristr strchr strrchr
strstr -- 查找字符串的首次出现,返回字符串从第一次出现的位置开始到该字符串的结尾或开始. stristr -- strstr 函数的忽略大小写版本 strchr -- strstr 函数的别 ...
- C#画图
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Dr ...
- REST_FRAMEWORK加深记忆-极致抽象,极致完结
余下的就是静心看官方文档了. 这个是最抽象的了. urls.py """tutorial URL Configuration The `urlpatterns` list ...
- 00 - Oracle体系结构课程内容
1.导论 自己把本书内容分为几个部分, (1)体系结构,(2)并发控制和事务,(3)物理存储, (4)其他. 嗯,拿到一个新的数据库,我们也要从这几个方面去认识它. 2.体系结构 3.Oracle ...