Skip to content

Commit c39a258

Browse files
authored
Create 2965. Find Missing and Repeated Values
1 parent 2eed6f7 commit c39a258

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <vector>
2+
using namespace std;
3+
4+
class Solution {
5+
public:
6+
vector<int> findMissingAndRepeatedValues(vector<vector<int>>& grid) {
7+
int n = grid.size();
8+
vector<int> res(2);
9+
vector<int> num(n * n + 1, 0);
10+
11+
for (int i = 0; i < n; i++) {
12+
for (int j = 0; j < n; j++) {
13+
if (num[grid[i][j]] == 1) {
14+
res[0] = grid[i][j];
15+
} else {
16+
num[grid[i][j]] = 1;
17+
}
18+
}
19+
}
20+
21+
for (int i = 1; i <= n * n; i++) {
22+
if (num[i] == 0) {
23+
res[1] = i;
24+
break;
25+
}
26+
}
27+
28+
return res;
29+
}
30+
};

0 commit comments

Comments
 (0)