We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 2eed6f7 + c39a258 commit bedda9bCopy full SHA for bedda9b
2965. Find Missing and Repeated Values
@@ -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