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. Tomcat 添加为系统服务 开机自动启动

    http://jingyan.baidu.com/article/a65957f4b12b8724e77f9b5a.html Tomcat是Apache 软件基金会(Apache Software F ...

  2. linux内核支持U-disk和U转串

    配置内核 make menuconfig,选中device驱动 Device Drivers ---->USB support--->USB Serial Converter suppor ...

  3. WPF教程二:布局之StackPanel面板

    应用程序界面设计中,合理的元素布局至关重要,它可以方便用户使用,并将信息清晰合理地展现给用户.WPF提供了一套功能强大的工具-面板(Panel),来控制用户界面的布局.你可以使用这些面板控件来排布元素 ...

  4. 各种api接口

    实用号码归属地查询(IP 地址,手机号码): 默认格式: http://api.liqwei.com/location/ (使用来访者的 IP 地址) 指定 IP 地址格式: http://api.l ...

  5. android activity lifecycle

    学习android的activity,之前一直没有去琢磨,今天正好了解一下activity生命周期. 参考链接: https://developer.android.com/guide/compone ...

  6. CentOS命令top下你不一定懂的cpu显示信息

    在使用top命令的时候会看到这么一行: 里面的各个值分别是什么意思呢? 今天被问到这个问题,发现答的不是很清楚.果然啊,天天用最多的top命令都还没摸透...惭愧...于是就查了些资料: 官方解释 C ...

  7. Python学习笔记(一)——基本知识点

    主要记录学习Python的历程和用于复习.查阅之用. 知识点: 数据类型(列表.元组.字典.集合) 帮助文档 函数(默认参数.可变参数.关键字参数.参数组合) 数据类型: 列表:list       ...

  8. ASP.NET动态添加用户控件的方法

    本文实例讲述了ASP.NET动态添加用户控件的方法.分享给大家供大家参考.具体实现方法如下: 为了让用户控件能ASP.NET页面实现动态添加,首先写一个接口IGetUCable,这个接口有一个函数,返 ...

  9. jquery注册文本框获取焦点清空,失去焦点赋值的简单实例

    在我们开发过程中特别是用户注册时会有一个效果,就是文本框获取焦点清空提示,如果用户没有输入信息失去焦点赋值上我们的提示语.   <html> <head> <meta h ...

  10. NLP入门相关——学习笔记

    近义词.一词多义 GPT.ELMO.Bert