Leetcode 223. Rectangle Area (Easy) (cpp)
2016-07-16 17:54
706 查看
Leetcode 223. Rectangle Area (Easy) (cpp)
Tag: Math
Difficulty: Easy
Tag: Math
Difficulty: Easy
/* 223. Rectangle Area (Easy) 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 are = (C - A) * (D - B) + (G - E) * (H -F); if (E >= C || G <= A || F >= D || H <= B) return are; else return are -= (min(C, G) - max(A, E)) * (min(D, H) - max(B, F)); } };
相关文章推荐
- C++基础之模板
- C++ cin输入流 详细用法
- C++拷贝构造函数(深拷贝,浅拷贝)
- NOIP2002提高组第1题 均分纸牌
- C++使用外部库开发的环境配置
- C语言学习之指针变量
- C语言类型转换
- C语言函数sscanf()的用法
- c++内存
- C语言冒泡排序算实现代码
- C/C++实战实用知识点记录
- C语言Side Effect与Sequence Point
- c++逐行读取写入txt文件的方法
- 【C语言基础】-03运算符
- C 语言操作符优先级和结合性
- C++ PP chapter Ⅶ C++的编程模块
- C++ 把输出结果写入到文件中
- C语言 程序 位运算
- C++Primer 变量和基本类型
- First Missing Positive