[Leetcode]Rectangle Area
2015-12-14 20:16
295 查看
Rectangle Area
Total Accepted: 24959 Total Submissions: 89043 Difficulty: 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.
Rectangle Area
Assume that the total area is never beyond the maximum possible value of int.
Credits:
Special thanks to @mithmatt for adding this problem, creating the above image and all test cases.
Subscribe to see which companies asked this question
Total Accepted: 24959 Total Submissions: 89043 Difficulty: 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.
Rectangle Area
Assume that the total area is never beyond the maximum possible value of int.
Credits:
Special thanks to @mithmatt for adding this problem, creating the above image and all test cases.
Subscribe to see which companies asked this question
[code]class Solution { public: int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { unsigned int totalArea = (C - A) * (D - B) + (G - E) * (H - F); unsigned long long hBig = max(D,H) - min(B,F); unsigned long long lBig = max(G,C) - min(A,E); if(hBig >= ((D - B) + (H - F)) || lBig >= ((C - A) + (G - E))) return totalArea; unsigned long long h = ((D - B) + (H - F)) - hBig; unsigned long long l = ((C - A) + (G - E)) - lBig; return totalArea - (unsigned long long)h * (unsigned long long)l; } };
相关文章推荐
- 文哲201512
- Mybatis前奏【Java Web 开发进化史】——万丈高楼从JDBC开始
- Android使用 LruCache 缓存图片
- Django 序列化
- stl智能指针和boost智能指针对比
- 【LEETCODE】36-Valid Sudoku
- poj--2337(输出欧拉路径)
- 1032. 挖掘机技术哪家强(20)
- 传递数据包
- 一些简单的网络流模型
- json处理复杂对象jsonConfig
- ThinkPHP--多表查询之join和table的用法
- HDU 1177 "Accepted today?" 水题
- 推送 -- 原理
- 将github上开源项目导入AndroidStudio中
- PAT 乙级 1007. 素数对猜想 (20)
- poj3685
- 字符集及其比较方式(Character Sets and Collations)
- Autofac全面解析系列(版本:3.5) – [使用篇(推荐篇):3.依赖注入]
- 怪怪的函数strtok