#593
Valid Square
expert · 1005 · lc medium +32 · verified · 44.9% accepted · 1,118 likes · top 28%
Description
Given four 2D points p1, p2, p3, and p4 each as [x, y] (in no particular order), return true if they form a valid square — four equal-length positive sides meeting at right angles — or false otherwise.
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
Code
1
2
3