【一天一道LeetCode】#223. Rectangle Area
来源:互联网 发布:2016网络零售交易额 编辑:程序博客网 时间:2024/05/17 21:59
一天一道LeetCode
本系列文章已全部上传至我的github,地址:ZeeCoder‘s Github
欢迎大家关注我的新浪微博,我的新浪微博
欢迎转载,转载请注明出处
(一)题目
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.
(二)解题
题目大意:求两个矩形总的覆盖面积。
解题思路:判断两个数组不重叠,满足C<=E||G<=A||F>=D||B>=H,
如果重叠求重叠面积:(min(C,G)-max(A,E))*(min(D,H)-max(B,F))。
下面是代码:
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); if(C<=E||G<=A||F>=D||B>=H) return total;//不重叠 return total - (min(C,G)-max(A,E))*(min(D,H)-max(B,F));//重叠 }};
0 0
- 【一天一道LeetCode】#223. Rectangle Area
- [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
- Belarusian State University & Kazakhstan Contest D Contest
- STM32学习笔记之中断向量表,MDK程序启动分析
- 以下代码共调用多少次拷贝构造函数:
- pair与排序
- Java学习笔记1——集合
- 【一天一道LeetCode】#223. Rectangle Area
- STM32经验心得(一)
- Java 线程池框架核心代码分析
- 安卓模拟器运行慢解决办法
- 分布式消息队列(2)
- 意外险知识总结
- 求助2015 Multi-University Training Contest 1_A(hdu 5288)
- python文件结构
- AsyncTask