-
Notifications
You must be signed in to change notification settings - Fork 0
/
645.hpp
40 lines (34 loc) · 786 Bytes
/
645.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
#ifndef LEETCODE_645_HPP
#define LEETCODE_645_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;
class Solution {
public:
vector<int> findErrorNums(vector<int> &nums) {
vector<int> res;
for (int n : nums) {
if (nums[abs(n) - 1] < 0) {
res.push_back(abs(n));
} else {
nums[abs(n) - 1] *= -1;
}
}
for (int i = 1; i <= nums.size(); ++i) {
if (nums[i - 1] > 0) {
res.push_back(i);
break;
}
}
return res;
}
};
#endif //LEETCODE_645_HPP