(java)Rectangle Area
来源:互联网 发布:查询淘宝页面历史快照 编辑:程序博客网 时间:2024/06/05 20:17
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.
思路:就是用两个矩形的面积和减去重叠部分的面积。求出重叠部分的面积就好,不难,就不在赘述了。
代码如下(已通过leetcode)
public class Solution {
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
//if(A==C || B==D || E==G || F==H) return 0;
int areaA=(C-A)*(D-B);
int areaB=(G-E)*(H-F);
int htop=Math.min(D, H);
int hbot=Math.max(B, F);
int wleft=Math.max(A, E);
int wright=Math.min(C, G);
if(htop>hbot && wright>wleft) return areaA+areaB-(htop-hbot)*(wright-wleft);
else return areaA+areaB;
}
- 【leetcode】Rectangle Area【java】
- (java)Rectangle Area
- [LintCode]Rectangle Area(Java)
- leetcode oj java Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- Rectangle Area
- web开发弹性盒模型flexbox新旧比较
- java代码与mysql语句的一些优化
- 【leetcode题解】【99.38】【E】Contains Duplicate II
- 掌握设计模式
- android_rpg 天龙群侠传
- (java)Rectangle Area
- Spring框架(二)--AOP面向切面编程
- 第9周项目3-稀疏矩阵的三元组表示的应用(3.2).cpp
- Making Sequences is Fun(简单枚举)
- 【ssh学习笔记】struts处理json异常之JSONWriter can not access a member of class org.springframework.aop.TruePoin
- 如何优化UITableView性能
- 第9周项目4-广义表算法库(4.1).cpp
- python读写Excel
- C#由指定数据生成灰度位图或者彩色位图