Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    593 - Valid Square\.

    Medium

    Given the coordinates of four points in 2D space p1, p2, p3 and p4, return true if the four points construct a square.

    The coordinate of a point <code>p<sub>i</sub></code> is represented as <code>x<sub>i</sub>, y<sub>i</sub></code>. The input is not given in any order.

    A valid square has four equal sides with positive length and four equal angles (90-degree angles).

    Example 1:

    Input: p1 = 0,0, p2 = 1,1, p3 = 1,0, p4 = 0,1

    Output: true

    Example 2:

    Input: p1 = 0,0, p2 = 1,1, p3 = 1,0, p4 = 0,12

    Output: false

    Example 3:

    Input: p1 = 1,0, p2 = -1,0, p3 = 0,1, p4 = 0,-1

    Output: true

    Constraints:

    • p1.length == p2.length == p3.length == p4.length == 2

    • <code>-10<sup>4</sup><= x<sub>i</sub>, y<sub>i</sub><= 10<sup>4</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Boolean validSquare(IntArray p1, IntArray p2, IntArray p3, IntArray p4)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait