forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0447.py
27 lines (22 loc) · 743 Bytes
/
0447.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution:
def numberOfBoomerangs(self, points):
"""
:type points: List[List[int]]
:rtype: int
"""
def dis(point1, point2):
return (point1[0] - point2[0])**2 + (point1[1] - point2[1])**2
result = 0
for i in points:
record = {}
for j in points:
if j != i:
distance = dis(i, j)
record[distance] = record.get(distance, 0) + 1
for val in record.values():
if val >= 2:
result += (val - 1)* val
return result
if __name__ == "__main__":
points = [[0,0],[1,0],[-1,0],[0,1],[0,-1]]
print(Solution().numberOfBoomerangs(points))