We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4b9f145 commit 01fae6cCopy full SHA for 01fae6c
python/FirstMissingPositive.py
@@ -0,0 +1,22 @@
1
+"""
2
+https://leetcode.com/problems/first-missing-positive/
3
+Given an unsorted integer array nums, return the smallest missing positive integer.
4
5
+class Solution(object):
6
+ def firstMissingPositive(self, nums):
7
+ """
8
+ :type nums: List[int]
9
+ :rtype: int
10
11
+ i=0
12
+ while i<len(nums):
13
+ correct=nums[i]-1
14
+ if nums[i]>0 and correct<len(nums) and nums[i]!=nums[correct]:
15
+ nums[i],nums[correct]=nums[correct],nums[i]
16
+ else:
17
+ i+=1
18
+ flag=0
19
+ for j in range(0,len(nums)):
20
+ if nums[j]-1!=j:
21
+ return j+1
22
+ return len(nums)+1
0 commit comments