[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): |