Leetcode 593 Solution
This article provides solution to leetcode question 593 (valid-square)
Access this page by simply typing in "lcs 593" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/valid-square
Solution
class Solution:
def dist(self, p1, p2):
return (p2[1] - p1[1]) * (p2[1] - p1[1]) + (p2[0] - p1[0]) * (p2[0] - p1[0])
def validSquare(self, p1: List[int], p2: List[int], p3: List[int], p4: List[int]) -> bool:
points = sorted([tuple(p1), tuple(p2), tuple(p3), tuple(p4)])
return self.dist(points[0], points[1]) != 0 and self.dist(points[0], points[1]) == self.dist(points[1], points[3]) == self.dist(points[3], points[2]) == self.dist(points[2], points[0]) \
and self.dist(points[0], points[3]) == self.dist(points[1], points[2])