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

Function search

javascript/0287-find-the-duplicate-number.js:174–183  ·  view source on GitHub ↗
(nums)

Source from the content-addressed store, hash-verified

172const isSame = (a, b) => a === b;
173
174const search = (nums) => {
175 for (let index = 0; index < nums.length; index++) {
176 /* Time O(N) */
177 const [num, arrayIndex] = [nums[index], index + 1];
178
179 if (!isSame(num, arrayIndex)) return num;
180 }
181
182 return nums.length;
183};
184
185/**
186 * https://leetcode.com/problems/find-the-duplicate-number/

Callers 1

findDuplicateFunction · 0.70

Calls 1

isSameFunction · 0.70

Tested by

no test coverage detected