-
Notifications
You must be signed in to change notification settings - Fork 2
/
q0041.hpp
45 lines (42 loc) · 1.01 KB
/
q0041.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// q0041.hpp
// LeetCode
//
// Created by 李凌 on 2020/9/30.
// Copyright © 2020 DoubleL. All rights reserved.
//
#ifndef q0041_hpp
#define q0041_hpp
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <numeric>
#include <stack>
#include <string>
using namespace std;
void question0041(){
class Solution {
public:
int firstMissingPositive(vector<int>& nums) {
size_t size = nums.size();
vector<bool> nums2(size + 2);
for (int i = 0; i < size; i++) {
int number = nums[i];
if (number > 0 && number <= size) {
nums2[number] = true;
}
}
int j = 1;
while (nums2[j++]);
return --j;
}
};
vector<int> nums = {3,4,-1,1};
int result = Solution().firstMissingPositive(nums);
printf("q0041_c++ result %d\n", result);
}
#endif /* q0041_hpp */