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 betweeni
andj
equals the distance betweeni
andk
(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
2
3
4
5
6
7
8 Input:
[[0,0],[1,0],[2,0]]
Output:
2
Explanation:
The two boomerangs are [[1,0],[0,0],[2,0]] and [[1,0],[2,0],[0,0]]
这道题似乎还没有什么好解法, 现在Runtime1368ms都可以beats 100%的C++提交…
现在已经不是了, 1000多ms的Runtime算是比较慢啦, 但是我暂时还没有时间来搞这道题…
使用双重循环+哈希表. 如果认为unordered_map的查询复杂度是O(1), 总体复杂度是O(n^2).
1 | class Solution { |