@Test void firstMissingPositive2() { Assert.assertEquals(3, firstMissingPositive.firstMissingPositive2(new int[]{1,2,0})); Assert.assertEquals(2, firstMissingPositive.firstMissingPositive2(new int[]{3,4,-1,1})); Assert.assertEquals(1, firstMissingPositive.firstMissingPositive2(new int[]{7,8,9,11,12})); }
public int firstMissingPositive2(int[] nums) { if (nums.length == 0) { return 1; } if (nums.length == 1) { return nums[0] == 1 ? 2 : 1; } int min = 1; while (contain(nums, min) || min < 1) { ++min; } return min; }
FirstMissingPositive { public int firstMissingPositive2(int[] nums) { if (nums.length == 0) { return 1; } if (nums.length == 1) { return nums[0] == 1 ? 2 : 1; } int min = 1; while (contain(nums, min) || min < 1) { ++min; } return min; } }
FirstMissingPositive { public int firstMissingPositive2(int[] nums) { if (nums.length == 0) { return 1; } if (nums.length == 1) { return nums[0] == 1 ? 2 : 1; } int min = 1; while (contain(nums, min) || min < 1) { ++min; } return min; }  }
FirstMissingPositive { public int firstMissingPositive2(int[] nums) { if (nums.length == 0) { return 1; } if (nums.length == 1) { return nums[0] == 1 ? 2 : 1; } int min = 1; while (contain(nums, min) || min < 1) { ++min; } return min; }  int firstMissingPositive(int[] nums); int firstMissingPositive2(int[] nums); }
FirstMissingPositive { public int firstMissingPositive2(int[] nums) { if (nums.length == 0) { return 1; } if (nums.length == 1) { return nums[0] == 1 ? 2 : 1; } int min = 1; while (contain(nums, min) || min < 1) { ++min; } return min; }  int firstMissingPositive(int[] nums); int firstMissingPositive2(int[] nums);  }