Skip to content

Commit 5a35c7f

Browse files
committed
Runtime: 295 ms (Top 90.42%) | Memory: 28 MB (Top 72.11%)
1 parent 9c2f499 commit 5a35c7f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
# Runtime: 295 ms (Top 90.42%) | Memory: 28 MB (Top 72.11%)
12
class Solution:
23
def firstMissingPositive(self, nums: List[int]) -> int:
34
mn = float('inf')
45
mx = 0
56
numsSet = set()
6-
7+
78
for i in range(len(nums) - 1, -1, -1):
89
if nums[i] > 0:
910
if nums[i] < mn:
@@ -12,11 +13,11 @@ def firstMissingPositive(self, nums: List[int]) -> int:
1213
mx = nums[i]
1314
numsSet.add(nums[i])
1415
del nums[i]
15-
16+
1617
if mn >= 2:
1718
return 1
1819
if len(numsSet) == mx:
1920
return mx + 1
2021
for i in range(2, len(numsSet) + 1):
2122
if i not in numsSet:
22-
return i
23+
return i

0 commit comments

Comments
 (0)