447. 回旋镖的数量

执行用时:600 ms, 在所有 Swift 提交中击败了100.00%的用户
内存消耗:13.5 MB, 在所有 Swift 提交中击败了100.00%的用户

题目链接:https://leetcode-cn.com/problems/number-of-boomerangs/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
func numberOfBoomerangs(_ points: [[Int]]) -> Int {
var ans = 0
let n = points.count
for i in 0 ..< n {
var hash: [Int: Int]=[:]
for j in 0 ..< n {
let x = points[i][0] - points[j][0]
let y = points[i][1] - points[j][1]
let dist = x*x + y*y
if hash[dist] != nil {
hash[dist]! += 1
}else {
hash[dist] = 1
}
}
for m in hash.values {
ans = ans + m*(m-1)
}
}
return ans
}
}

447. 回旋镖的数量
https://pisces34.github.io/2021/09/14/leetcode/447/
发布于
2021年9月14日
许可协议