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

Function moveFast

javascript/0287-find-the-duplicate-number.js:253–266  ·  view source on GitHub ↗
(nums, start = 0)

Source from the content-addressed store, hash-verified

251};
252
253const moveFast = (nums, start = 0) => {
254 let [slow, fast] = [nums[start], nums[nums[start]]];
255
256 const isSame = () => slow === fast;
257 while (!isSame()) {
258 /* Time O(N) */
259 slow = nums[slow];
260 fast = nums[nums[fast]];
261 }
262
263 fast = start;
264
265 return [slow, fast];
266};
267
268const moveSlow = (nums, slow, fast) => {
269 const isSame = () => slow === fast;

Callers 1

findDuplicateFunction · 0.70

Calls 1

isSameFunction · 0.70

Tested by

no test coverage detected