【Leetcode Algorithm】Rectangle Area
来源:互联网 发布:playclub陈诗涵mod数据 编辑:程序博客网 时间:2024/05/16 17:20
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 class Solution { public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { //判断是否相交 if(C<E||A>G||B>H||D<F){ //若不相交,则返回两个矩形的面积之和 return (C-A)*(D-B)+(G-E)*(H-F); } else{ //若相交,则两个矩形的面积之和减去相交部分面积 return (C-A)*(D-B)+(G-E)*(H-F)-(Math.min(C,G)-Math.max(A,E))*(Math.min(D,H)-Math.max(B,F)); } }}
0 0
- 【Leetcode Algorithm】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
- [LeetCode] Rectangle Area
- LeetCode: Rectangle Area
- Leetcode 223 Rectangle Area
- linux下weblogic11g安装成功后,启动报错Getting boot identity from user
- 链式队列
- 防SQL注入
- 学习网址
- 使用系统下载管理类DownloadManager
- 【Leetcode Algorithm】Rectangle Area
- 关于交叉编译器默认体系结构的问题
- 攻克GRE阅读难关的方法
- 润乾填报表的时间参数设置
- 【Leetcode Algorithm】Invert Binary Tree
- Service 服务基础学习
- 常用排序算法总结
- Apache ServiceMix 介绍
- weka初步一