From 82961900b5fc6da114de7e6784bd64ce771ec302 Mon Sep 17 00:00:00 2001 From: urvashigupta7 Date: Sat, 3 Oct 2020 09:14:02 +0530 Subject: [PATCH] first-missing-positive --- FirstMissingPositive.java | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 FirstMissingPositive.java diff --git a/FirstMissingPositive.java b/FirstMissingPositive.java new file mode 100644 index 0000000..6107004 --- /dev/null +++ b/FirstMissingPositive.java @@ -0,0 +1,41 @@ + +import java.util.ArrayList; +import java.util.List; + +class Solution { + public static void main(String []args){ + int []nums={1,2,0}; + int target=7; + System.out.println(firstMissingPositive(nums)); + } + public static int firstMissingPositive(int[] nums) { + int size=segregate(nums); + if(size==0){ + return 1; + } + for(int i=0;i=0&&abs-10){ + nums[abs-1]=-nums[abs-1]; + } + } + for(int i=0;i0){ + return i+1; + } + } + return size+1; + } + public static int segregate(int []nums){ + int start=-1; + for(int i=0;i0){ + start++; + int temp=nums[i]; + nums[i]=nums[start]; + nums[start]=temp; + } + } + return start+1; + } +} \ No newline at end of file