[LeetCode]447. Number of Boomerangs
题目
Given n
points in the plane that are all pairwise distinct, a “boomerang” is a tuple of points (i, j, k)
such that the distance between i
and j
equals the distance between i
and k
(the order of the tuple matters).
Find the number of boomerangs. You may assume that n will be at most 500 and coordinates of points are all in the range [-10000, 10000] (inclusive).
Example:
1 | Input: |
难度
Easy
方法
对于每个point
,用一个map
统计各个距离d
下对应的其他point
的个数n
,即map
的key
为距离d
,value
为距离该point
为d
的其他point
的个数n
。然后An
取2
,即n*(n-1)
。最后将各个point
对应的n*(n-1)
累加即可
python代码
1 | class Solution(object): |