LeetCode--223. Rectangle Area
来源:互联网 发布:香蕉网络免费频道 编辑:程序博客网 时间:2024/04/29 18:38
Problem:
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
Credits:
Special thanks to @mithmatt for adding this problem, creating the above image and all test cases.
Answer:
public class Solution { public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { //计算分离的两块长方形面积area1和area2 int area1 = Math.abs((C-A)*(D-B)); int area2 = Math.abs((E-G)*(F-H)); if(B>H || D<F || C<E || A>G) return area1+area2; //确定叠加区域的两个X和两个Y int maxX = Math.min(C,G); int minX = Math.max(A,E); int maxY = Math.min(D,H); int minY = Math.max(B,F); //计算叠加区域面积 int area = (maxX-minX)*(maxY-minY); return area1+area2-area; }}
0 0
- [leetcode] 223.Rectangle Area
- [leetcode] 223. Rectangle Area
- 223. Rectangle Area LeetCode
- #leetcode# 223. Rectangle Area
- leetcode 223. Rectangle Area
- LeetCode--223. Rectangle Area
- LeetCode *** 223. Rectangle Area
- LeetCode 223. Rectangle Area
- leetcode-223. Rectangle Area
- LeetCode-223.Rectangle Area
- 223.[Leetcode]Rectangle Area
- leetcode 223. Rectangle Area
- 【leetcode】223. Rectangle Area
- [Leetcode]223. Rectangle Area
- LeetCode - 223. Rectangle Area
- LeetCode 223. Rectangle Area
- LeetCode 223. Rectangle Area
- LeetCode 223. Rectangle Area
- 只关心零件的Buider
- hrbust/哈理工oj 1126 Final Destination II【矩阵快速幂+递推】
- MaterialDrawer使用指南
- Android数据库greenDAO框架用法和源码分析
- jws,axis2,Xfire以及cxf对比
- LeetCode--223. Rectangle Area
- 拒绝装饰模式
- unity3D OnTriggerEnter和OnCollisionEnter的一点个人心得(主要讲区别)
- 【小镇的技术天梯】C语言,冒泡、快速、希尔、选择排序
- 触摸java常量池
- Python debug——TypeError: unhashable type(list/set/dict)
- 架构的本质
- oc 和 swift 互相调用
- android Animation 动画