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

  1. public class Solution {
  2. public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
  3. int area = (C-A)*(D-B) + (G-E)*(H-F);
  4. if (A >= G || B >= H || C <= E || D <= F) {
  5. return area;
  6. }
  7. int top = Math.min(D, H);
  8. int bottom = Math.max(B, F);
  9. int left = Math.max(A, E);
  10. int right = Math.min(C, G);
  11. return area - (top-bottom)*(right-left);
  12.  
  13. }
  14. }

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. Hibernate使用createSqlQuery进行模糊查询时找不到数据

    1. 首先明确一点,使用createSqlQuery如下两种方式的占位符都可以使用,这个在官方的文档可以查到. 注意使用模糊查询时,赋值两边不可以添加单引号. Query query = sess.c ...

  2. WCF客户端获取服务器返回数据报错

    错误信息:An error occurred while receiving the HTTP response to http://127.0.0.1/SIHIS/Infection/PubExec ...

  3. debian配置网络

    http://blog.csdn.net/ypist/article/details/8513274 vim /etc/resolv.conf   配置域名服务器 search test.ivic.o ...

  4. HTTP API 设计指南(结尾)

    前言 这篇指南介绍描述了 HTTP+JSON API 的一种设计模式,最初摘录整理自 Heroku 平台的 API 设计指引 Heroku 平台 API 指引. 这篇指南除了详细介绍现有的 API 外 ...

  5. SpringMVC拦截器简单使用

    一.拦截器的配置 1.传统的配置 Xml代码   <bean class="org.springframework.web.servlet.mvc.annotation.Default ...

  6. atitit.javascript调用java in swt attilax 总结

    atitit.javascript调用java in swt attilax 总结 1. BrowserFunction 简单介绍1 1.1. BrowserFunction 能够分为三类: 1 1. ...

  7. 【JavaNIO的深入研究4】内存映射文件I/O,大文件读写操作,Java nio之MappedByteBuffer,高效文件/内存映射

    内存映射文件能让你创建和修改那些因为太大而无法放入内存的文件.有了内存映射文件,你就可以认为文件已经全部读进了内存,然后把它当成一个非常大的数组来访问.这种解决办法能大大简化修改文件的代码.fileC ...

  8. CentOS7怎么修改命令行启动

    root用户下直接执行命令: systemctl set-default multi-user.target 然后reboot即可.

  9. 算法--将Excel列索引转换成默认标识

    使用POI导入Excel时,有时对模板进行验证,假如第1行第1列错误,此时的rowIndex=columnIndex=0,与平时看到的Excel行列标记相比不太直观,因此通过相应的算法将其转换成人们熟 ...

  10. ASP.NET自带对象JSON字符串与实体类的转换

    关于JSON的更多介绍,请各位自行google了解!如果要我写的话,我也是去Google后copy!嘿嘿,一直以来很想学习json,大量的找资料和写demo,总算有点了解! 切入正题! 还是先封装一个 ...