Description:https://leetcode.com/problems/rectangle-area/

public class Solution {
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int area = (C-A)*(D-B) + (G-E)*(H-F);
if (A >= G || B >= H || C <= E || D <= F) {
return area;
}
int top = Math.min(D, H);
int bottom = Math.max(B, F);
int left = Math.max(A, E);
int right = Math.min(C, G);
return area - (top-bottom)*(right-left); }
}

LeetCode——Rectangle Area的更多相关文章

  1. [LeetCode] Rectangle Area 矩形面积

    Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...

  2. [leetcode] Rectangle Area

    Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...

  3. LeetCode Rectangle Area (技巧)

    题意: 分别给出两个矩形的左下点的坐标和右上点的坐标,求他们覆盖的矩形面积? 思路: 不需要模拟,直接求重叠的部分的长宽就行了.问题是如果无重叠部分,注意将长/宽给置为0. class Solutio ...

  4. [LeetCode] 850. Rectangle Area II 矩形面积之二

    We are given a list of (axis-aligned) rectangles.  Each rectangle[i] = [x1, y1, x2, y2] , where (x1, ...

  5. [LeetCode] 223. Rectangle Area 矩形面积

    Find the total area covered by two rectilinearrectangles in a 2D plane. Each rectangle is defined by ...

  6. LeetCode 223. 矩形面积(Rectangle Area)

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

  7. 【leetcode】Contains Duplicate & Rectangle Area(easy)

    Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your funct ...

  8. 【刷题-LeetCode】223. Rectangle Area

    Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...

  9. [LeetCode] Rectangle Overlap 矩形重叠

    A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bot ...

随机推荐

  1. java中volatile关键字的含义<转>

    在java线程并发处理中,有一个关键字volatile的使用目前存在很大的混淆,以为使用这个关键字,在进行多线程并发处理的时候就可以万事大吉. Java语言是支持多线程的,为了解决线程并发的问题,在语 ...

  2. Ubuntu下,dpkg安装出错的修复

    参考 http://www.khattam.info/2009/08/04/solved-subprocess-pre-removal-script-returned-error-exit-statu ...

  3. win7怎么把软件加入开机启动项

    点击开机菜单进入. 2 然后点击菜单栏中的所有程序. 3 在所有程序中找到‘启动’,这个启动就是开机启动项来的. 4 右键进行打开启动项. 5 把快捷方式复制到开机启动项中.如果找不到快捷方式可以右键 ...

  4. jump display

    查找了数据库,再在while里拼接成json是很麻烦的,所以,jump display 获得数组 <?php header("Content-Type:text/html; chars ...

  5. Json---Windows下使用Jsoncpp

    上述Json解析使用的是Jsoncpp,要使用Jsoncpp,得做如下几步的配置: 1. 首先从http://sourceforge.net/projects/jsoncpp/下载,压缩包大约105k ...

  6. e553. 作为浏览器访问URL

    // See also e551 精简的Applet try { URL url = new URL(getDocumentBase(), "http://hostname.com/page ...

  7. 启动vsftpd失败

    启动vsftpd失败 在使用centos时, 要用ftp上传文件, 但是一到脚本的ftp命令就会出错: rpm -Uvh http://mirror.centos.org/centos/6/os/i3 ...

  8. 3D游戏与计算机图形学中的数学方法-四元数

    说实话关于四元数这一节真的是不好懂,因为里面涉及到好多数学知识,单说推出来的公式就有很多.不怕大家笑话,对于四元数的学习我足足花了两天的时间,包括整理出这篇文章.在前面一章我写到了“变换”,这也是总结 ...

  9. Linux(Ubuntu)下搭建ASP.NET Core环境

    今天来学习一下ASP.NET Core 运行在Ubuntu中.无需安装mono . 环境 Ubuntu 14.04.4 LTS 服务器版 全新安装系统. 下载地址:http://mirrors.neu ...

  10. el表达式取值优先级

    不同容器中存在同名值时,从作用范围小到大的顺序依次尝试取值:pageContext->request->session->application