MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / kClosest

Function kClosest

javascript/0937-k-closest-points-to-origin.js:8–14  ·  view source on GitHub ↗
(points, K)

Source from the content-addressed store, hash-verified

6 * @return {number[][]}
7 */
8var kClosest = function (points, K) {
9 const distance = ([x, y]) => x * x + y * y;
10
11 points.sort((a, b) => distance(a) - distance(b));
12
13 return points.slice(0, K);
14};
15
16/**
17 * https://leetcode.com/problems/k-closest-points-to-origin/

Callers

nothing calls this directly

Calls 3

distanceFunction · 0.85
quickSelectFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected