【Leetcode】Rectangle Area && Classic Prob: Overlap Rectangle
来源:互联网 发布:python中延时函数 编辑:程序博客网 时间:2024/05/08 07:37
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.
————————————————————————————————————————
不废话,直接上代码,题目是让求总面积,无非是overlap不overlap情况,基于overlap rect的判断,简单之极。
public class Solution { public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int total = (C-A)*(D-B) + (G-E)*(H-F); //A,B -> bottomleft C,D topright; E,F bottomleft, G,H topright; if(C <= E || G <= A) return total; if(B >= H || F>= D) return total; int i = Math.max(A,E); int j = Math.min(C,G); int p = Math.max(B,F); int q = Math.min(D,H); return total - (p-q) * (i-j); }}
0 0
- 【Leetcode】Rectangle Area && Classic Prob: Overlap Rectangle
- 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
- 【Deep Learning】Review of Designing Deep Networks for Surface Normal Estimation
- Nginx安装与配置
- Java类与文件
- CGAL1_1 Three Points and One Segment
- 安装完ubuntu系统后要做的事(以ubuntu15.10为例)
- 【Leetcode】Rectangle Area && Classic Prob: Overlap Rectangle
- 七小时 Theano 入门(Day 2)
- 【Leetcode】Search a 2D Matrix II
- 彻底弄懂AngularJS中的transclusion
- 为什么那些每三年跳一次槽的人越跳越好? - 震撼
- 【Leetcode】Sliding Window Maximum
- 小试爬虫,爬CSC.EDU.CN
- leetcode36.Valid Sudoku
- 评测脚本