Number of Boomerangs LeetCode solution in JavaScript

1
var numberOfBoomerangs = function (points) {
2
const POINTS_LEN = points.length;
3
let result = 0;
4

5
for (let i = 0; i < POINTS_LEN; i++) {
6
const hash = new Map();
7

8
for (let j = 0; j < POINTS_LEN; j++) {
9
if (i === j) continue;
10
const [x1, y1] = points[i];
11
const [x2, y2] = points[j];
12
const dis = Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2);
13
const value = hash.get(dis) ?? 0;
14

15
if (value > 0) result += value * 2;
16
hash.set(dis, value + 1);
17
}
18
}
19

20
return result;
21
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0