Skip to content

Commit

Permalink
41
Browse files Browse the repository at this point in the history
  • Loading branch information
isinsuarici committed Mar 8, 2022
1 parent d21a4d9 commit 7d79671
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions H_41_FirstMissingPositive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution:
def firstMissingPositive(self, nums: List[int]) -> int:
n = len(nums)
nums.sort()
if(nums[0]>1 or nums[n-1]<0):
return 1
for i in range(n-1):
if (nums[i+1]>1) and (nums[i]<0):
return 1
if nums[i+1]-abs(nums[i])>1:
return nums[i]+1
return nums[n-1]+1

0 comments on commit 7d79671

Please sign in to comment.