From 840bacad634916ee0be8bdcc5d7a0cdae9509722 Mon Sep 17 00:00:00 2001 From: Akshay Agarwal Date: Sun, 24 Oct 2021 12:05:38 +0530 Subject: [PATCH] solution for problem first missing positive no cpp --- algorithms/cpp/first_missing_positive.cpp | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 algorithms/cpp/first_missing_positive.cpp 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; + } +};