diff --git a/algorithms/cpp/first_missing_positive.cpp b/algorithms/cpp/first_missing_positive.cpp new file mode 100644 index 00000000..27e6de61 --- /dev/null +++ b/algorithms/cpp/first_missing_positive.cpp @@ -0,0 +1,37 @@ +// problem : https://leetcode.com/problems/first-missing-positive/ + +class Solution { +public: + int firstMissingPositive(vector& nums) { + long int l = nums.size(); + if(l==0) + return 1; + if(l==1) + return nums[0]==1?2:1; + long int f=0,i; + for( i=0;i=0) + nums[in]=-nums[in]; + } + + for(int i=st;i=0) + return i+1-st; + return l+1-st; + } +};