package leetcode;

/**
 * https://leetcode.com/problems/first-missing-positive/
 */
public class Problem41 {
    public int firstMissingPositive(int[] nums) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem41 prob = new Problem41();
        System.out.println(prob.firstMissingPositive(new int[]{1, 2, 0})); // 3
        System.out.println(prob.firstMissingPositive(new int[]{3, 4, -1, 1})); // 2
        System.out.println(prob.firstMissingPositive(new int[]{1, 2, 6, 5})); // 3
        System.out.println(prob.firstMissingPositive(new int[]{3, 2, 5, -3, -1})); // 1
        System.out.println(prob.firstMissingPositive(new int[]{})); // 1
        System.out.println(prob.firstMissingPositive(new int[]{0})); // 1
        System.out.println(prob.firstMissingPositive(new int[]{2})); // 1
        System.out.println(prob.firstMissingPositive(new int[]{1})); // 2
        System.out.println(prob.firstMissingPositive(new int[]{1, 1})); // 2
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -190,16 +190,36 @@
     
-// TODO%0A
+if (nums.length == 0) %7B%0A    
     
@@ -229,17 +229,684 @@
  return 
-0
+1;%0A        %7D%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            if (nums%5Bi%5D %3E= 1 && nums%5Bi%5D %3C nums.length) %7B%0A                swap(nums, nums%5Bnums%5Bi%5D%5D - 1, nums%5Bi%5D);%0A            %7D%0A        %7D%0A        System.out.println(Arrays.toString(nums));%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            if (nums%5Bi%5D != i + 1) %7B%0A                return i + 1;%0A            %7D%0A        %7D%0A        return nums%5Bnums.length - 1%5D + 1;%0A    %7D%0A%0A    private static void swap(int%5B%5D nums, int i, int j) %7B%0A        if (i %3C 0 %7C%7C i %3E= nums.length %7C%7C j %3C 0 %7C%7C j %3E= nums.length) %7B%0A            return;%0A        %7D%0A        int tmp = nums%5Bi%5D;%0A        nums%5Bi%5D = nums%5Bj%5D;%0A        nums%5Bj%5D = tmp
 ;%0A    %7D%0A
@@ -997,88 +997,10 @@
 ();%0A
-        System.out.println(prob.firstMissingPositive(new int%5B%5D%7B1, 2, 0%7D)); 
 //
- 3%0A
     
@@ -1062,27 +1062,23 @@
 t%5B%5D%7B
-3, 4, -1, 1
+1, 2, 0
 %7D)); // 
 2%0A  
@@ -1065,34 +1065,36 @@
 %7B1, 2, 0%7D)); // 
-2%0A
+3%0A//
         System.o
@@ -1144,26 +1144,16 @@
 t%5B%5D%7B
-1, 2, 6, 5
 %7D)); // 
 3%0A  
@@ -1148,18 +1148,20 @@
 %7D)); // 
-3%0A
+1%0A//
         
@@ -1219,23 +1219,9 @@
 t%5B%5D%7B
-3, 2, 5, -3, -1
+0
 %7D));
@@ -1218,32 +1218,34 @@
 nt%5B%5D%7B0%7D)); // 1%0A
+//
         System.o
@@ -1283,32 +1283,33 @@
 itive(new int%5B%5D%7B
+2
 %7D)); // 1%0A      
@@ -1294,32 +1294,34 @@
 nt%5B%5D%7B2%7D)); // 1%0A
+//
         System.o
@@ -1367,25 +1367,25 @@
 w int%5B%5D%7B
-0
+1
 %7D)); // 
 1%0A      
@@ -1368,34 +1368,36 @@
  int%5B%5D%7B1%7D)); // 
-1%0A
+2%0A//
         System.o
@@ -1443,25 +1443,28 @@
 w int%5B%5D%7B
-2
+1, 1
 %7D)); // 
 1%0A      
@@ -1455,18 +1455,20 @@
 %7D)); // 
-1%0A
+2%0A//
         
@@ -1522,25 +1522,31 @@
 w int%5B%5D%7B
-1
+2, 2, 4
 %7D)); // 
 2%0A      
@@ -1533,25 +1533,25 @@
 2, 4%7D)); // 
-2
+1
 %0A        Sys
@@ -1594,32 +1594,41 @@
 itive(new int%5B%5D%7B
+0, 2, 2, 
 1, 1%7D)); // 2%0A  
@@ -1623,17 +1623,17 @@
 %7D)); // 
-2
+3
 %0A    %7D%0A%7D

Update problem 41