[Leetcode 207, Easy] Rectangle Area
来源:互联网 发布:in作图软件 编辑:程序博客网 时间:2024/06/11 01:33
Problem:
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.
Analysis:
Solutions:
C++:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int shared_area; if(G <= A || E >= C || B >= H || F >= D) shared_area = 0; else { vector<int> x_coordinates; x_coordinates.push_back(A); x_coordinates.push_back(C); x_coordinates.push_back(E); x_coordinates.push_back(G); sort(x_coordinates.begin(), x_coordinates.end()); vector<int> y_coordinates; y_coordinates.push_back(B); y_coordinates.push_back(D); y_coordinates.push_back(F); y_coordinates.push_back(H); sort(y_coordinates.begin(), y_coordinates.end()); shared_area = (x_coordinates[2] - x_coordinates[1]) * (y_coordinates[2] - y_coordinates[1]); } int area_1 = (C - A) * (D - B); int area_2 = (G - E) * (H - F); return area_1 + area_2 - shared_area; }Java:
Python:
0 0
- [Leetcode 207, Easy] Rectangle Area
- LeetCode #223 - Rectangle Area - Easy
- Leetcode 223. Rectangle Area (Easy) (cpp)
- 223. Rectangle Area [easy] (Python)
- 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
- springMVC+myBatis+Atomikos 多数据源分布式事务 oracle 、mysql 、sqlserver 数据源
- activity堆栈式管理
- TCP洪水攻击(SYN Flood)的诊断和处理
- 【转载】android 中Xml里面的id重名问题
- SQLServer游标(Cursor)简介和使用说明
- [Leetcode 207, Easy] Rectangle Area
- Hadoop编程实例--数据去重
- chrome模拟手机和web的切换方式
- C++中的(:)与(::)的区别
- C# 并行编程 之 ThreadPool的基本使用
- ocx 中处理回车相应的问题
- NoSQL数据库-MongoDB和Redis
- 一个有关程序运行时间的小测试
- 同步数据