# leetcode 593. Valid Square 练习

Given the coordinates of four points in 2D space, return whether the four points could construct a square.

The coordinate (x,y) of a point is represented by an integer array with two integers.

##### Example:
``````Input: p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,1]
Output: True``````

Note:
All the input integers are in the range [-10000, 10000].
A valid square has four equal sides with positive length and four equal angles (90-degree angles).
Input points have no order.

``````class Solution(object):
def validSquare(self, p1, p2, p3, p4):
"""
:type p1: List[int]
:type p2: List[int]
:type p3: List[int]
:type p4: List[int]
:rtype: bool
"""
points = [p1, p2, p3, p4]
return len({(a[0]-b[0])**2 + (a[1]-b[1])**2 for a in points for b in points}) == 3 and \
len(set(map(tuple, points))) == 4``````

``````{(a[0]-b[0])**2 + (a[1]-b[1])**2 for a in points for b in points}
＃相当与
for a in points:
for b in points:
a[0]-b[0])**2 + (a[1]-b[1])**2
#然后集合去重
len(set(map(tuple, points)))
＃这句的意思是看有没有重复的点``````

(=￣ω￣=)··· 暂无内容！

2

0

2

2