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

Function negativeMarking

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

Source from the content-addressed store, hash-verified

197};
198
199const negativeMarking = (nums) => {
200 for (let i = 0; i < nums.length; i++) {
201 /* Time O(N) */
202 const curr = Math.abs(nums[i]);
203
204 const isNegative = nums[curr] < 0;
205 if (isNegative) return curr;
206
207 nums[curr] *= -1;
208 }
209
210 return -1;
211};
212
213const restoreToPositiveNumbers = (nums) => {
214 for (let i = 0; i < nums.length; i++) {

Callers 1

findDuplicateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected