my python solution


  • 0
    W
    • find the distance
    • none of the distance is 0, two unique distances
        def validSquare(self, p1, p2, p3, p4):
            dist = []
            ps = [p1, p2, p3, p4]
            for i in range(4):
              for j in range(i+1, 4, 1):
                dist.append((ps[i][0] - ps[j][0])**2 + (ps[i][1] - ps[j][1])**2)
            return len(set(dist)) == 2 and all(x != 0 for x in dist)
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.