-
Notifications
You must be signed in to change notification settings - Fork 0
/
leet448.cpp
60 lines (40 loc) · 955 Bytes
/
leet448.cpp
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
46
47
48
49
50
51
52
53
54
#include <vector>
#include <iostream>
using namespace std;
class Solution {
public:
vector<int> findDisappearedNumbers(vector<int>& nums) {
int n = nums.size();
vector<int> res;
for (int i=0; i<n; ++i) {
int k = abs(nums[i]) - 1;
cout << k << " " << endl;
nums[k] = nums[k] > 0 ? -nums[k] : nums[k];
}
for (int i=0; i<n; ++i) {
if (nums[i] > 0) {
res.push_back(i+1);
}
}
return res;
}
};
int main() {
Solution sol;
vector<int> nums;
vector<int> res;
nums.push_back(4);
nums.push_back(3);
nums.push_back(2);
nums.push_back(7);
nums.push_back(8);
nums.push_back(2);
nums.push_back(3);
nums.push_back(1);
res = sol.findDisappearedNumbers(nums);
for (int i=0; i<res.size(); ++i) {
cout << res[i] << " ";
}
cout << endl;
return 0;
}