Leetcode: Rectangle Area
2015-12-18 00:48
267 查看
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. Rectangle Area 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) { int area3 = 0; int area1 = (C-A) * (D-B); int area2 = (G-E) * (H-F); if (C<=E || G<=A || H<=B || D<=F) area3 = 0; else area3 = (Math.min(C,G)-Math.max(A,E)) * (Math.min(D,H)-Math.max(B,F)); return area1 + area2 - area3; } }
相关文章推荐
- 今天同事周斌在预生产环境的服务器上犯了一个致命的错误
- 部署和调优 1.9 samba 部署和优化-3
- 张国祥老师应邀在浙江衢州讲授流程建设与优化课程
- 宁波麒麟贸易集团公司连续三天举办流程管理知识竞赛
- 终于用ADB连上平板了
- 【Beta阶段】第六次Scrum Meeting!
- Winform自定义控件—Button(上)
- Java 初始化与清理
- WordPress升级错误:class-wp-filesystem-direct.php on line 122
- Swift项目兼容Objective-C问题汇总
- KMP字符串查找算法
- [jquery]高级篇--标签选择
- 【开源】简单4步搞定QQ登录,无需什么代码功底【无语言界限】
- 来自阿里妈妈的iconfont(转)
- hdu 1698 线段树 区间更新 区间求和
- mysql的排障之一
- 简单工厂模式
- 流量分析
- 关键字break代码优化片段
- try catch finally 和 return 解析