LeetCode-223.Rectangle Area

原创 2016年05月30日 15:16:08

https://leetcode.com/problems/rectangle-area/

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.

一开始用了愚蠢的办法,用了各种判断

参考后(http://www.cnblogs.com/sunshisonghit/p/4580069.html)得到下面代码

public int ComputeArea(int A, int B, int C, int D, int E, int F, int G, int H) 
    {
        int areaAB = (C - A) * (D - B) + (G - E) * (H - F);
        int left = Math.Max(A, E);
        int right = Math.Min(C, G);
        int top = Math.Min(D, H);
        int down = Math.Max(B, F);
        if (left < right && down < top)
            return areaAB - (right - left) * (top - down);
        return areaAB;
    }


版权声明:本文为博主原创文章,未经博主允许不得转载。

LeetCode-223. Rectangle Area (JAVA)求矩形覆盖面积

LeetCode-223. Rectangle Area (JAVA)求矩形覆盖面积

[leetcode] 223.Rectangle Area

题目: Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defin...

Leetcode_223_Rectangle Area

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/46868363 Find the total area...

LeetCode #223 - Rectangle Area - Easy

ProblemFind the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is def...
  • Arcome
  • Arcome
  • 2016年12月14日 17:41
  • 147

LeetCode 223. Rectangle Area(两个矩形的复合面积计算)

原题网址:https://leetcode.com/problems/rectangle-area/ Find the total area covered by two rectilinear...
  • jmspan
  • jmspan
  • 2016年04月05日 00:48
  • 1023

Rectangle Area - LeetCode 223

题目描述: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is d...
  • bu_min
  • bu_min
  • 2015年06月08日 22:04
  • 240

[Leetcode] 223. Rectangle Area 解题报告

题目: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle ...

Leetcode 223. Rectangle Area

223. Rectangle Area Total Accepted: 46967 Total Submissions: 150715 Difficulty: Easy Find the to...

leetcode 223. Rectangle Area

边界条件太恶心 特别是两个正方形在对方内部都没有点,但是却相交的情况,佩服出题人够严谨。class Solution { public: int computeArea(int A, int...

[LeetCode]--223. Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:LeetCode-223.Rectangle Area
举报原因:
原因补充:

(最多只允许输入30个字)