-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
29 lines (28 loc) · 839 Bytes
/
solution.py
File metadata and controls
29 lines (28 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
Code generated by https://github.com/goodstudyqaq/leetcode-local-tester
"""
try:
from utils.python3.help import *
except ImportError:
pass # In leetcode environment, we don't need to import the help file.
class Solution:
def firstMissingPositive(self, nums: List[int]) -> int:
n = len(nums)
nums.append(0)
for i in range(n):
if nums[i] <= 0 or nums[i] > n:
nums[i] = -1
for i in range(n):
if nums[i] == -1:
continue
if nums[i] == n + 1:
continue
now = nums[i]
while now >= 1 and now <= n:
go = nums[now]
nums[now] = n + 1
now = go
now = 1
while now <= n and nums[now] == n + 1:
now += 1
return now