Last active
November 24, 2021 12:46
-
-
Save Bloofer/4cc61f80f7e48e01af8d2684a3b53f61 to your computer and use it in GitHub Desktop.
fmp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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