LeetCode——Rectangle Area
来源:互联网 发布:电脑录音软件 编辑:程序博客网 时间:2024/06/05 20:50
题目:
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.
解答:
class Solution {public: int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { bool rc1IsEmpty = D <= B || C <= A; bool rc2IsEmpty = H <= F || G <= E; if (rc1IsEmpty && rc2IsEmpty) { return 0; } else if (rc1IsEmpty) { return (H - F) * (G - E); } else if (rc2IsEmpty) { return (D - B) * (C - A); } int size; if(B >= H || F >= D || E >= C || A >= G) { size = 0; } else { int dx = (H < D ? H : D) - (F > B ? F : B); int dy = (C < G ? C : G) - (A > E ? A : E); size = dx * dy; } return (H - F) * (G - E) + (D - B) * (C - A) - size; }};
0 0
- LeetCode——Rectangle Area
- leetcode——223——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
- Android:Layout_weight的深刻理解
- leetcode 012 Integer to Roman
- cxf生成客户端代码
- Python Appium实现中文输入分享
- phpmailer使用教程及实例演示
- LeetCode——Rectangle Area
- style、currentStyle、getComputedStyle的应用
- LIBRARY_PATH和LD_LIBRARY_PATH环境变量的区别
- ajax简单入门
- 使用指针取得Color的RGB值和透明度值
- java面向对象-this
- 编外的编外话
- OpenWrt的用处
- Sublime2 运行NodeJS