Skip to content

Instantly share code, notes, and snippets.

@Bloofer
Last active November 24, 2021 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bloofer/4cc61f80f7e48e01af8d2684a3b53f61 to your computer and use it in GitHub Desktop.
Save Bloofer/4cc61f80f7e48e01af8d2684a3b53f61 to your computer and use it in GitHub Desktop.
fmp
class Solution {
private:
bool hash[500001] = {0, };
public:
int firstMissingPositive(vector<int>& nums) {
int cnt;
for (int i=0; i<nums.size(); i++){
if(nums[i] <= 0 || nums[i] > nums.size()) continue;
else hash[nums[i]] = true;
}
for (int i=1; i<500000; i++){
if(!hash[i]) return i;
}
return nums.size() + 1;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment