-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (43 loc) · 1.05 KB
/
main.cpp
File metadata and controls
46 lines (43 loc) · 1.05 KB
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
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
vector<int> findMissingAndRepeatedValues(vector<vector<int>>& grid)
{
// construct set of elements and find repeating value
int n = (int)grid.size();
vector<int> values(n * n + 1, 0);
int a, b;
for (const auto& row: grid)
{
for (int el: row)
{
if (values[el] != 0)
a = el;
else
values[el] = 1;
}
}
// find missing value
for (int i = 1; i <= n * n; ++i)
{
if (i == a)
continue;
else if (values[i] == 0)
{
b = i;
break;
}
}
vector<int> answer = {a, b};
return answer;
}
};
int main()
{
vector<vector<int>> grid = {{1, 3}, {2, 2}};
vector<int> answer = Solution().findMissingAndRepeatedValues(grid);
cout << "[" << answer[0] << ", " << answer[1] << "]\n";
return 0;
}