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

Function quickSelect

javascript/0937-k-closest-points-to-origin.js:31–42  ·  view source on GitHub ↗
(points, target, left, right)

Source from the content-addressed store, hash-verified

29};
30
31const quickSelect = (points, target, left, right) => {
32 const mid = getMid(points, left, right);
33
34 const isTarget = mid === target - 1;
35 if (isTarget) return;
36
37 const isTargetGreater = mid < target - 1;
38 if (isTargetGreater) quickSelect(points, target, mid + 1, right);
39
40 const isTargetLess = target - 1 < mid;
41 if (isTargetLess) quickSelect(points, target, left, mid - 1);
42};
43
44const swap = (points, left, right) =>
45 ([points[left], points[right]] = [points[right], points[left]]);

Callers 1

kClosestFunction · 0.70

Calls 1

getMidFunction · 0.70

Tested by

no test coverage detected