[leetcode] Rectangle Area
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.
Special thanks to @mithmatt for adding this problem, creating the above image and all test cases
class Solution
{
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H)
{
int x1 = A > E ? A : E;
int y1 = B > F ? B : F;
int x2 = C > G ? G : C;
int y2 = D > H ? H : D; int x = x2 - x1, y = y2 - y1;
int s = ;
if(x> && y>)
s = x * y; return (C-A)*(D-B)+(G-E)*(H-F) - s;
}
};
[leetcode] Rectangle Area的更多相关文章
- [LeetCode] Rectangle Area 矩形面积
Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...
- LeetCode——Rectangle Area
Description:https://leetcode.com/problems/rectangle-area/ public class Solution { public int compute ...
- LeetCode Rectangle Area (技巧)
题意: 分别给出两个矩形的左下点的坐标和右上点的坐标,求他们覆盖的矩形面积? 思路: 不需要模拟,直接求重叠的部分的长宽就行了.问题是如果无重叠部分,注意将长/宽给置为0. class Solutio ...
- [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 矩形面积
Find the total area covered by two rectilinearrectangles in a 2D plane. Each rectangle is defined by ...
- LeetCode 223. 矩形面积(Rectangle Area)
223. 矩形面积 223. Rectangle Area 题目描述 在二维平面上计算出两个由直线构成的矩形重叠后形成的总面积. 每个矩形由其左下顶点和右上顶点坐标表示,如图所示. LeetCode2 ...
- 【leetcode】Contains Duplicate & Rectangle Area(easy)
Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your funct ...
- 【刷题-LeetCode】223. Rectangle Area
Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...
- [LeetCode] Rectangle Overlap 矩形重叠
A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bot ...
随机推荐
- 【PRML读书笔记-Chapter1-Introduction】1.1 Example:Polynomial Curve Fitting
书中给出了一个典型的曲线拟合的例子,给定一定量的x以及对应的t值,要你判断新的x对应的t值多少. 任务就是要我们去发现潜在的曲线方程:sin(2πx) 这时就需要概率论的帮忙,对于这种不确定给t赋何值 ...
- 交叉编译mips平台上valgrind
STEP 1:下载最新版本的valgrind:http://www.valgrind.org/downloads/valgrind-3.9.0.tar.bz2 目前支持的平台,在官网上列表如下:{x8 ...
- andriod手机签到应用服务器设计
最近导师要求我和另一个同学开发一个手机上课签到应用,我负责客户端和服务器之间的通信架构编写和数据的存储 本人大学四年只用过汇编和C/C++,因此对andriod开发还是一窍不通,花了一个星期写出来了基 ...
- LeetCode-304. Range Sum Query 2D - Immutable
Description: Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by ...
- js 实现各种排序
一 冒泡排序 一万个随机数排序五次执行时间分别为 362 389 361 372 408 毫秒 var arr=[]; for(var j=0;j<10000;j++){ arr.push(Ma ...
- jQuery--捕获键盘敲击
功能 当页面加载完成后,用户键盘按下某个键后,jQuery能够捕获到一个数字,从而执行一系列动作. 格式 1 2 3 4 5 6 7 8 9 10 11 12 $(function(){ $ ...
- Java魔法堂:以Windows服务的形式运行Java程序
一.前言 由于防止维护人员误操作关闭Java控制台程序,因此决定将其改造为以Windows服务的形式运行.弄了一个上午总算搞定了,下面记录下来,以供日后查阅. 二.Java Service Wrapp ...
- BlocksKit初见:一个支持将delegate转换成block的Cocoa库
简介 项目主页: https://github.com/zwaldowski/BlocksKit BlocksKit 是一个开源的框架,对 Cocoa 进行了扩展,将许多需要通过 delegate 调 ...
- mysql update时报错You are using safe update mode
在使用mysql执行update的时候,如果不是用主键当where语句,会报如下错误,使用主键用于where语句中正常. ) Error Code: . You are using safe upda ...
- 2016校招内推 -- 腾讯SNG前端 -- 面试经历
也是让某湿兄帮忙内推,然后过了四五天,电话打来了 一面: 1.首先是简单的自我介绍 2.你觉得一个前端工程师应该具备什么技能 比如用户体验这个方面他就贵问你具体的例子 3.让你设计一个web站点,假如 ...