Leetcode Problem 1401. Circle and Rectangle Overlapping

1401. Circle and Rectangle Overlapping

Leetcode Solutions

Calculating the Closest Point and Distance

  1. Clamp the x-coordinate of the circle's center to the rectangle's x-boundaries to find the closest x-coordinate on the rectangle to the circle's center.
  2. Clamp the y-coordinate of the circle's center to the rectangle's y-boundaries to find the closest y-coordinate on the rectangle to the circle's center.
  3. Calculate the squared distance between the circle's center and the closest point on the rectangle.
  4. If the squared distance is less than or equal to the square of the radius, return true indicating overlap; otherwise, return false.
UML Thumbnail

Brute Force Checking of Points within the Rectangle

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...