这道题典型就是从小到大枚举整个过程,那核心就是要提高给定序列的查询速度,所以就可以模拟一个哈希表即可
class Solution {
public:
int findMissMin(vector<int>& nums) {
//这道题不需要处理冲突,只需要开个桶排序(桶插法)来模拟哈希表即可
int n = nums.size();
vector<bool> hash(n + 1);
for(int x: nums)
if(x >= 1 && x <= n)
hash[x] = true;
for(int i = 1;i <= n;i ++)
if(!hash[i])
return i;
return n + 1;
}
};