Leetcode Problem 593. Valid Square

593. Valid Square

Leetcode Solutions

Approach # Using Sorting

  1. Sort the points based on their x-coordinates, and in case of a tie, on their y-coordinates.
  2. Check if the distances between p0p1, p1p3, p3p2, and p2p0 are all equal (these are the sides of the square).
  3. Check if the distances between p0p3 and p1p2 are equal (these are the diagonals of the square).
  4. If both conditions are met, return true, indicating the points form a square.
  5. If any condition fails, return false.
UML Thumbnail

Approach # Brute Force

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...