leetcode 223. Rectangle Area
来源:互联网 发布:java 汽车租赁管理系统 编辑:程序博客网 时间:2024/06/02 10:12
解题思路:
关键在于对重复区域面积的计算
原题目:
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.
AC解,C++代码,菜鸟一个,请大家多多指正
class Solution {public: int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { if (C > G) { return computeArea(E, F, G, H, A, B, C, D); } int area1 = (C - A) * (D - B); int area2 = (G - E) * (H - F); int area3 = 0; if (C <= E || B >= H || D <= F) { return area1 + area2; } area3 = (C - max(E, A)) * (min(H,D) - max(B, F)); return area1 + area2 - area3; }};
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
- oracle 中将number类型的数据转化成指定格式的小数
- request和respose的跳转区别
- standard BAPI(BAPI_ACC_DOCUMENT_POST) to park document
- IOS openURL的使用(iOS调用系统电话、浏览器、地图、邮件等)
- Android获取全局Context的方式
- leetcode 223. Rectangle Area
- spring MVC配置详解
- ls: error while loading shared libraries: libcap.so.2: cannot open shared object file: No such file
- Oracle中自动生成的guid与.Net中的guid的交互
- tomcat端口被占用
- IOS 多用类型常量,少用#define预处理指令
- 深入理解Activity启动流程
- android 白屏问题或者设置页面的闪屏
- How to Write High-DPI Applications 参考链接