LeetCode 223. Rectangle Area
来源:互联网 发布:latex软件 编辑:程序博客网 时间:2024/05/16 07:47
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) { int l1 = max(A, E); int l2 = max(B, F); int r1 = min(C, G); int r2 = min(D, H); int num = (r1 - l1) * (r2 - l2); if(l1 >= r1 || l2 >= r2) num = 0; return (C - A) * (D - B) + (G - E) * (H - F) - num; }};
0 0
- [leetcode] 223.Rectangle Area
- [leetcode] 223. Rectangle Area
- 223. Rectangle Area LeetCode
- #leetcode# 223. Rectangle Area
- leetcode 223. Rectangle Area
- LeetCode--223. Rectangle Area
- LeetCode *** 223. Rectangle Area
- LeetCode 223. Rectangle Area
- leetcode-223. Rectangle Area
- LeetCode-223.Rectangle Area
- 223.[Leetcode]Rectangle Area
- leetcode 223. Rectangle Area
- 【leetcode】223. Rectangle Area
- [Leetcode]223. Rectangle Area
- LeetCode - 223. Rectangle Area
- LeetCode 223. Rectangle Area
- LeetCode 223. Rectangle Area
- LeetCode 223. Rectangle Area
- JAVA面试算法小记
- TableView优化之高度缓存
- LeetCode 258 Add Digits
- 【华为机试】题目+解答+自己不足+提升
- java项目一------OA报名与审核管理系统
- LeetCode 223. Rectangle Area
- 个性水彩人像效果
- android中java中的开方
- **AJAX** ajax的使用
- 计算机科学导论学习笔记
- const详谈
- poj 2635 素数打表+同余求模定理+千进制
- 游戏资源的制作和下载
- C#枚举和结构体