Number of Boomerangs LeetCode solution in Python

1
class Solution:
2
def numberOfBoomerangs(self, points: List[List[int]]) -> int:
3
def sq(a):
4
return a * a
5

6
def euclid(a, b, c, d):
7
dist = sq(a - c) + sq(b - d)
8
return sq(dist)
9

10
n = len(points)
11
res = 0
12
for i in range(n):
13
count = defaultdict(lambda: 0)
14
for j in range(n):
15
d = euclid(points[i][0], points[i][1], points[j][0], points[j][1])
16
res += count[d] * 2
17
count[d] += 1
18

19
return res

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0