[leetcode] 223. Rectangle Area 解题报告
2015-12-28 15:02
330 查看
题目链接:https://leetcode.com/problems/rectangle-area/
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.
思路:一道简答的数学题,意思就是求这两个矩形覆盖的面积,也就是要去掉重复的面积。
代码如下:
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 area = (C-A)*(D-B) + (G-E)*(H-F); if(!(B >= H || F>=D || A >=G ||E>=C)) { int tem = (min(C, G) -max(A, E)) * (min(D, H) -max(B, F)); area -= tem; } return area; } };
相关文章推荐
- 天津Uber优步司机奖励政策(12月28日到12月29日)
- jquery实现导航栏鼠标点击后实行背景高亮,点击离开恢复(超级简单!!!!),jquery导航栏
- 12864液晶模块驱动
- 浅谈现在的社区o2o超市怎么样呢?
- [maven+javancss] Can't process temp ncss xml file.
- python使用cx_oracle连接oracle数据库
- Socket 深度探索 4 PHP (一)
- 南京Uber优步司机奖励政策(12月28日到1月3日)
- 1602/2002/2004液晶模块驱动
- 12.28 AJAX 返回TEXT值
- iptables 实现端口转发
- mtk pwm&&linux timer
- pg_rman 实现对postgresql数据库的备份,恢复与管理
- 文件拷贝的实现
- svn常用操作
- Android 学习笔记
- 根据分类ID获得所有子ID和所有父ID
- **Eclipse Access Restriction**
- 如何用GAT抓取log
- 长沙Uber优步司机奖励政策(12月28日到1月3日)