Skip to content

Commit

Permalink
Create First Missing Positive.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
guptaa98 authored Oct 1, 2020
1 parent 1dfc488 commit 021b6f1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions First Missing Positive.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution {
public:
int firstMissingPositive(vector<int>& nums)
{
set<int>s;
int c=0;
if(nums.size()==0)
{
return 1;
}
for(int i=0;i<nums.size();i++)
{
if(nums[i]>0)
{
s.insert(nums[i]);
}
}
for(int i=1;i<=nums.size()+1;i++)
{
if(s.find(i)==s.end())
{
c=i;
return c;
}
}
return 0;
}
};

0 comments on commit 021b6f1

Please sign in to comment.