Simple Java Solution With O(n) and O(1)


#1

public class Solution {
public int firstMissingPositive(ArrayList A) {
Collections.sort(A);
int curr = 1;
for(int i =0;i<A.size();i++){
if(A.get(i) <=0) continue;
if(curr == A.get(i)){
curr++;
continue;
}
if(curr < A.get(i)){
break;
}
}
return curr;
}
}


#2

umm, Collections.sort(A) has O(nlogn) complexity, this solution is ofc not O(n)