# Hard-题目29：41. First Missing Positive

Given an unsorted integer array, find the first missing positive integer.

For example,
Given [1,2,0] return 3,
and [3,4,-1,1] return 2.

（这真是原创的）用hashset就好了，判断集合中是否有n却没有n+1.

public class Solution {
public int firstMissingPositive(int[] nums) {
HashSet<Integer> set = new HashSet<Integer>();
int max=0;
for(int num:nums) {
if(num>max)
max=num;
}
if(!set.contains(1))
return 1;
for(int i=1;i<max;i++) {
if(set.contains(i)&&!set.contains(i+1))
return i+1;
}
return max+1;
}

}

3ms,3.77%，1ms,82.72%
cmershen的碎碎念：

#### LeetCode(41) First Missing Positive

2014-12-31 08:08:19

#### [leetcode]41. First Missing Positive,C++/python实现，hard难度

2016-06-16 19:37:56

#### 41. First Missing Positive Leetcode Python

2015-02-03 04:40:20

#### leetCode 41.First Missing Positive (第一个丢失的正数) 解题思路和方法

2015-07-10 10:25:58

#### First Missing Positive -- LeetCode

2014-03-13 04:31:27

#### [leetcode-41]First Missing Positive(java)

2015-07-10 22:18:31

#### 【LeetCode】First Missing Positive 解题报告

2014-12-28 21:00:14

#### First Missing Positive:一道对测试样例十分困惑的题目

2017-12-22 20:40:55

#### Leetcode：First Missing Positive

2013-10-23 16:27:01

#### 41. First Missing Positive

2015-07-22 12:37:43