【第22期】观点:IT 行业加班,到底有没有价值?

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

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

Leetcode - Rectangle Area

Find the total area covered by two rectilinear rectangles in a <span style="font-weight: b

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

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

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.[img]https://leetcode.com/static/images/problemset/rectangle_area.png[/img] Assume that the total area is never beyond the maxi

LeetCode----223. Rectangle Area 2个矩形和

223. Rectangle Area 2个矩形和
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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