From 2c02f96c7183a278d1e0323e8da2a232fe50ed32 Mon Sep 17 00:00:00 2001 From: mukul Date: Tue, 22 Oct 2024 20:28:17 +0530 Subject: [PATCH] 41. First Missing Positive --- .../Algorithms/hard/First_Missing_Positive.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/LeetcodeProblems/Algorithms/hard/First_Missing_Positive.js b/LeetcodeProblems/Algorithms/hard/First_Missing_Positive.js index c85597b..8bb6ed3 100644 --- a/LeetcodeProblems/Algorithms/hard/First_Missing_Positive.js +++ b/LeetcodeProblems/Algorithms/hard/First_Missing_Positive.js @@ -35,17 +35,17 @@ If all elements are in their correct positions, the function returns the next po * @return {number} */ var firstMissingPositive = function(nums) { - const n = nums.length + const n = nums.length; for (let i = 0; i < n; i++) while (nums[i] > 0 && nums[i] <= n && nums[nums[i] - 1] !== nums[i]) - [nums[nums[i] - 1], nums[i]] = [nums[i], nums[nums[i] - 1]] + [nums[nums[i] - 1], nums[i]] = [nums[i], nums[nums[i] - 1]]; for (let i = 0; i < n; i++) if (nums[i] !== i + 1) - return i + 1 + return i + 1; - return n + 1 + return n + 1; }; module.exports.firstMissingPositive = firstMissingPositive; \ No newline at end of file