直接循环遍历O(n^3) 想办法转为O(n^2)
根据点到点间的距离相同 可以建立一个字典{两点间距离:出现次数}
两层循环第一层找i,第二层找j,k
class Solution:
def numberOfBoomerangs(self, points):
"""
:type points: List[List[int]]
:rtype: int
"""
n=len(points)
res=0
for i in range(n):
dict1={}
for j in range(n):
d=(points[i][0]-points[j][0])**2+(points[i][1]-points[j][1])**2
if d in dict1:
dict1[d]+=1
else:
dict1[d]=1
for val in dict1.values():
res+=(val-1)*val
return res