LeetCode题解:Rectangle Area
来源:互联网 发布:手机拍照翻译软件 编辑:程序博客网 时间:2024/05/16 23:39
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.
题意:求出两个交叠矩形的面积
解决思路:矩形总面积减去交叠区域面积
代码:
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int together; if (C <= E || A >= G || B >= H || D <= F) { together = 0; } else { int x = Math.min(C, G) - Math.max(A, E); int y = Math.min(D, H) - Math.max(B, F); together = x * y; } return (C - A) * (D - B) + (G - E) * (H - F) - together; }
0 0
- LeetCode题解:Rectangle Area
- LeetCode 题解(193) : Rectangle Area
- 【E】【51】【leetcode题解】Rectangle Area
- leetcode题解分析_223. Rectangle Area
- leetcode Rectangle Area
- [LeetCode] Rectangle Area
- leetcode--Rectangle Area
- [LeetCode]Rectangle Area
- [leetcode] Rectangle Area
- Rectangle Area - LeetCode 223
- leetcode-Rectangle Area[math]
- leetCode 之 Rectangle Area
- leetcode 223: Rectangle Area
- [leetcode]Rectangle Area
- leetcode[223]:Rectangle Area
- LeetCode Rectangle Area
- [leetcode][math] Rectangle Area
- #leetcode#Rectangle Area
- zoj2100 Seeding
- ps学习笔记五(通道与图层)
- actionbar的下阴影线如何消除
- ActivityGroup返回键获取焦点处理
- Sql Server的存储过程基本知识
- LeetCode题解:Rectangle Area
- Valid Parentheses
- 第七篇:C/C++动态内存的分配问题
- Spring中控制反转实例
- javascript递归与闭包
- Android读取SD卡内容
- Java基础学习总结—Java对象的序列化和反序列化
- 16进制颜色代码记忆规律/
- iOS新手必看之全貌