Skip to content

Commit 5142c72

Browse files
authored
Update 41-first-missing-positive.js
1 parent efc88e4 commit 5142c72

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

41-first-missing-positive.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ const firstMissingPositive = function(nums) {
2323
* @return {number}
2424
*/
2525
function firstMissingPositive(nums) {
26-
const A = nums
2726
const n = nums.length
2827
for (let i = 0; i < n; i++) {
29-
while (A[i] > 0 && A[i] <= n && A[A[i] - 1] !== A[i]) swap(A, i, A[i] - 1)
28+
while (nums[i] > 0 && nums[i] <= n && nums[nums[i] - 1] !== nums[i])
29+
swap(nums, i, nums[i] - 1)
3030
}
3131

3232
for (let i = 0; i < n; i++) {
33-
if (A[i] !== i + 1) return i + 1
33+
if (nums[i] !== i + 1) return i + 1
3434
}
3535
return n + 1
3636
}
3737

3838
function swap(arr, i, j) {
39-
let tmp = arr[i]
39+
const tmp = arr[i]
4040
arr[i] = arr[j]
4141
arr[j] = tmp
4242
}

0 commit comments

Comments
 (0)