LeetCode 223. Rectangle Area
2016-07-22 01:53
387 查看
223. Rectangle Area
My Submissions QuestionEditorial Solution
Total Accepted: 34834 Total Submissions: 117121 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.
My Submissions QuestionEditorial Solution
Total Accepted: 34834 Total Submissions: 117121 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.
class Solution { public: int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int maxae = A > E ? A : E; int mincg = C > G ? G : C; int maxfb = F > B ? F : B; int minhd = H > D ? D : H; int overlap; if(maxae >= mincg || maxfb >= minhd) overlap = 0; else overlap = (mincg - maxae) * (minhd - maxfb); return (C - A) * (D - B) + (G - E) * (H - F) - overlap; } };
相关文章推荐
- LeetCode 299. Bulls and Cows
- 算法--列(java实现)
- 判断滚动条到底部的JS代码
- LeetCode 190. Reverse Bits
- LeetCode 20. Valid Parentheses
- 50个必备的实用jQuery代码段
- 12个用得着的JQuery代码片段
- LeetCode 19. Remove Nth Node From End of List
- LeetCode 290. Word Pattern
- LeetCode 58. Length of Last Word
- 统计项目源码行数的Java代码
- LeetCode 203. Remove Linked List Elements
- LeetCode 38. Count and Say
- java实现鼠标和键盘动作后台监听(未测试)
- LeetCode 203. Remove Linked List Elements
- 利用aosv库实现各种滚动与组件的互动
- LeetCode 225. Implement Stack using Queues
- LeetCode 14. Longest Common Prefix
- CSS3实现10种Loading效果
- Android适配——采用Values-dpi-wSize X hSize 模式,并分析原理