Using sort().So maybe not a O(n) solutions...

class Solution {

public:

int firstMissingPositive(vector<int>& nums) {

sort(nums.begin(), nums.end());

int res = 1;

for (int i=0; i<nums.size(); i++){

if (nums[i] == res)

res++;

else if (nums[i]>res)

break;

}

return res;

}

};

*Can someone tell me how to put my code in right way? QAQ*