国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

[LeetCode] 223. Rectangle Area

JayChen / 2958人閱讀

Problem

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.

Example:

Input: A = -3, B = 0, C = 3, D = 4, E = 0, F = -1, G = 9, H = 2
Output: 45
Note:

Assume that the total area is never beyond the maximum possible value of int.

Solution
class Solution {
    public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        int a1 = (C-A)*(D-B);
        int a2 = (G-E)*(H-F);
        int left = Math.max(A,E);
        int right = Math.min(C,G);
        int top = Math.min(D,H);
        int bottom = Math.max(B,F);
        if (left < right && bottom < top) return a1+a2-(right-left)*(top-bottom);
        else return a1+a2;
    }
}

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/73014.html

相關(guān)文章

  • leetcode363. Max Sum of Rectangle No Larger Than K

    摘要:思路一暴力循環(huán)如果我們將矩陣中的每個子矩陣都枚舉出來,并計(jì)算其元素和,從而得出小于的最大值即可。 題目要求 Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that its sum is no larger than k. E...

    nemo 評論0 收藏0
  • [Leetcode] Rectangle Area 矩形面積

    摘要:數(shù)學(xué)法復(fù)雜度時間空間思路基本的數(shù)學(xué)題,考察的是我們能否全面的考慮到所有可能。如果兩個矩形沒有重疊部分,則直接計(jì)算兩個矩形面積之和就行了。因?yàn)閮蓚€矩形的坐標(biāo)都可能比對方小,所以我們一共有四種可能情況是不重疊的。 Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. ...

    Cheng_Gang 評論0 收藏0
  • [LeetCode/LintCode] Construct the Rectangle

    Problem For a web developer, it is very important to know how to design a web pages size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose l...

    sf_wangchong 評論0 收藏0
  • [LeetCode] 84. Largest Rectangle in Histogram

    Problem Given n non-negative integers representing the histograms bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. showImg(https://segmentfault.com/img...

    BaronZhang 評論0 收藏0
  • [Leetcode] Largest Rectangle (in Histogram) 最大矩形

    摘要:以此類推,如果一直到棧為空時,說明剛出來的豎條之前的所有豎條都比它自己高,不然不可能棧為空,那我們以左邊全部的寬度作為長方形的寬度。 Largest Rectangle in Histogram Given n non-negative integers representing the histograms bar height where the width of each bar...

    鄒強(qiáng) 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<