"Leetcode-Interview algorithm classic-java implementation" "223-rectangle area (rectangular region)"

Source: Internet
Author: User

"223-rectangle Area (rectangular region)" "leetcode-Interview algorithm classic-java Implementation" "All topics Directory Index" code Download "Https://github.com/Wang-Jun-Chao" Original Question

Find the total area covered by and rectilinear rectangles in a 2D plane.

Each rectangle was defined by its bottom left corner and top right corner as shown in the figure.
Rectangle Area
Assume the total area is never beyond the maximum possible value of int.

Main Topic

Calculates the area covered by a total of two rectangles.

Thinking of solving problems

The method is calculated as the area of the rectangle 1 + the area of the rectangle 2-two rectangles with a common covering area.

Code Implementation

Algorithm implementation class

Import java.util.*; Public classSolution { Public int Computearea(intAintBintCintDintEintFintGintH) {LongArea = (Long) (c-a) * (d-b) + (Long) (G-E) * (H-F);//Math.min (C, G) represents the smallest edge of the right side        //Math.max (A, E) indicates the largest edge of the left side        //The subtraction below will result in an array of more than a medium, to enlarge the data range        Longwidth = Math.max ((Long) Math.min (C, G)-(Long) Math.max (A, E),0);//Math.min (D, H) indicates the smallest edge of the top edge        //Math.max (B, F) indicates the largest edge of the bottom edge        LongHeight = Math.max ((Long) Math.min (D, H)-(Long) Math.max (B, F),0);return(int) (Area-width * height); }}
Evaluation Results

  Click on the picture, the mouse does not release, drag a position, release after the new window to view the full picture.

Special Instructions Welcome reprint, Reprint please indicate the source "http://blog.csdn.net/derrantcm/article/details/48084065"

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Leetcode-Interview algorithm classic-java implementation" "223-rectangle area (rectangular region)"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.