<h3><a title="题目描述" href="https://leetcode-cn.com/problems/valid-square/">题目描述</a></h3>
![image.png](https://i.loli.net/2020/02/21/2qcXHL36htJ48Qa.png)
<h4>我的解法</h4>
<pre class="EnlighterJSRAW" data-enlighter-language="python">import math
class Solution:
def validSquare(self, p1: List[int], p2: List[int], p3: List[int], p4: List[int]) -> bool:
def getdistance(x,y):
return math.sqrt(pow(x[0]-y[0],2) + pow(x[1]-y[1],2))
res = []
point = [p1,p2,p3,p4]
for i in range(0,4):
for j in range(i + 1,4):
_ = getdistance(point[i],point[j])
res.append(_)
if len(set(res)) != 2 or 0 in set(res):
return False
else:
return True
</pre>
<p> </p>
<h4>Note:</h4>
<ul>
<li>其实有很多直觉上觉得很简单的东西 细细考虑还是不太容易很快给出正确的解法的</li>
<li>判断四点是否构成正方形,两两之间的距离是否仅有2种(边&对角线)且不为0即可</li>
</ul>
Leetcode593 有效的正方形