Skip to content
This repository has been archived by the owner on Sep 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #93 from soham0-0/find-missing-positive
Browse files Browse the repository at this point in the history
Added Solution of 0041 First Missing Positive - Issue #52
  • Loading branch information
vJechsmayr authored Oct 1, 2020
2 parents ad6c2f8 + 366341e commit 54ec103
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions LeetCode/0041_find_missing_positive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution:
def firstMissingPositive(self, nums: List[int]) -> int:
hasOne = False;
for i in range(len(nums)):
if(nums[i]==1):
hasOne = True
if(nums[i]<0):
nums[i] = 0

if not hasOne:
return 1

for i in range(len(nums)):
if(abs(nums[i])>0 and abs(nums[i])<=len(nums)):
if(nums[abs(nums[i])-1]==0):
nums[abs(nums[i])-1]=-1
elif(nums[abs(nums[i])-1]>0):
nums[abs(nums[i])-1]*=-1

for i in range(len(nums)):
if nums[i]>=0:
return i+1

return len(nums)+1

0 comments on commit 54ec103

Please sign in to comment.