题意:给出两个矩形,求其面积和

思路:两个矩形可能相交,在求相交面积时,左下角取两个矩形左下角的最大值 ,右上角取两个矩形对应坐标的最小值 ,如果求得的左下角大于右下角,说明不相交,面积为两个矩形面积之和,否则为两个矩形面积之和减去相交面积。

代码如下:

public class Solution
{public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {int x1 = Math.max(A, E), y1 = Math.max(B, F);int x2 = Math.min(C, G), y2 = Math.min(D, H);int areacross = 0;if (x1 > x2 || y1 > y2) areacross = 0;else areacross =  (x2 - x1) * (y2 - y1);int area1 = (C - A) * (D - B);int area2 = (G - E) * (H - F);return area1 + area2 - areacross;}
}

LeetCode Rectangle Area相关推荐

  1. LeetCode——223. 矩形面积(Rectangle Area)[中等]——分析及代码(C++)

    LeetCode--223. 矩形面积[Rectangle Area][中等]--分析及代码[C++] 一.题目 二.分析及代码 1. 几何计算 (1)思路 (2)代码 (3)结果 三.其他 一.题目 ...

  2. leetcode 850. Rectangle Area II | 850. 矩形面积 II(递归分割未重叠矩形)

    题目 https://leetcode.com/problems/rectangle-area-ii/ 题解 没有看懂官方答案,评论区有一种解法写的挺通俗的: Clean Recursive Solu ...

  3. LeetCode 850. Rectangle Area II

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

  4. Leetcode题目:Rectangle Area

    题目: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defin ...

  5. leetcode 223. Rectangle Area | 223. 矩形面积(Java)

    题目 https://leetcode.com/problems/rectangle-area/ 类似问题:蓝桥杯 BASIC-18 基础练习 矩形面积交 题解 本题的重点在于如何计算重叠部分的面积, ...

  6. 223. Rectangle Area

    题目: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defin ...

  7. Rectangle Area

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

  8. Leet Code OJ 223. Rectangle Area [Difficulty: Easy]

    题目: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defin ...

  9. [Leetcode] Max Area of Island 最大岛屿面积

    Max Area of Island 最新更新请见:https://yanjia.me/zh/2019/02/... Given a non-empty 2D array grid of 0's an ...

最新文章

  1. 项目2---机柜和物理服务器
  2. 深入理解编译优化之循环展开和粗化锁
  3. Text2SQL 语义解析数据集、解决方案、paper资源整合项目
  4. 用C#实现软件自动更新
  5. react文字滚动插件_【赠书】Preact(React)核心原理详解
  6. 交出娃哈哈,宗庆后还是不放心?
  7. 模拟线性调制系统的仿真
  8. 数据分析Power BI数据建模教程(三)——如何优化数据模型
  9. Netty 启动过程源码分析 (本文超长慎读)(基于4.1.23)
  10. python使用redis做缓存_Python的Flask框架使用Redis做数据缓存的配置方法
  11. 谷歌开源 Embedding Projector 高维数据可视化--转自开源中国
  12. driver接管当前浏览器
  13. alt+f2无法切换 linux,X 冻结: 无法通过 Ctrl + Alt + F2/F3 切换到虚拟终端(其实已经切过去了, 只是屏幕没有更新)...
  14. 【2021-MOOC-浙江大学-陈越、何钦铭-数据结构】树-中
  15. 【目标检测】K-means计算anchors
  16. 接口要怎么测试?接口自动化可以怎么做?
  17. 贝索斯的蓝色起源完成第五次太空旅游,将 6 人送入亚轨道飞行;三星英特尔频出招追赶台积电;
  18. python 箱线图的绘制方法
  19. 树莓派实现USB存储设备自动挂载
  20. Integer 和 int 的区别

热门文章

  1. ThinkPHP如何判断一个更新操作是否成功
  2. 阚凯力:四核终端发展需软硬件相互促进
  3. python第三方库排行-Python模块汇总(常用第三方库)
  4. 笔记本电脑下载python视频教程-Python的Jupyter Notebook入门教程
  5. python不能处理excel文件-别以为Python的pandas不能处理非规范Excel数据
  6. python数据类型-Python3基本数据类型(一、数字类型)
  7. python横向柱状图-python绘制横向水平柱状条形图Bar
  8. python绘制3d图形-Python基于matplotlib实现绘制三维图形功能示例
  9. python pdf-有没有好一点的读取 PDF 的 Python 包?
  10. 为何python不好找工作k-为何有人说Python不好找工作?