bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 391. Perfect Rectangle

391. Perfect Rectangle

Leetcode Solutions

Corner Counting Approach

  1. Initialize variables to track the total area and a set to store unique corners.
  2. Loop through each rectangle in the input list.
  3. For each rectangle, calculate its area and add it to the total area.
  4. For each of the four corners of the current rectangle, add or remove them from the set based on their presence.
  5. After processing all rectangles, check if the set contains exactly four corners.
  6. Calculate the area of the bounding rectangle formed by these four corners.
  7. Compare the total area of small rectangles with the area of the bounding rectangle.
  8. Return true if they match and the set contains exactly four corners, otherwise return false.
UML Thumbnail

Edge Counting Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...