缺失的第一个正整数_牛客题霸_牛客网 (nowcoder.com)
给定一个无重复元素的整数数组nums,请你找出其中没有出现的最小的正整数
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param nums int整型vector
* @return int整型
*/
int minNumberDisappeared(vector<int>& nums) {
// write code here
//依次遍历,将数据放到mp里
unordered_map<int,int> map;
for(auto a : nums){
map[a]++;
}
//从1开始,如果在mp中找到了就++ ,返回第一个没找到的
int a = 1;
while(map.find(a) != map.end()){
a++;
}
return a;
}
};