Skip to content

Commit

Permalink
Create 2965. Find Missing and Repeated Values (#732)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Mar 6, 2025
2 parents 2eed6f7 + c39a258 commit bedda9b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 2965. Find Missing and Repeated Values
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <vector>
using namespace std;

class Solution {
public:
vector<int> findMissingAndRepeatedValues(vector<vector<int>>& grid) {
int n = grid.size();
vector<int> res(2);
vector<int> num(n * n + 1, 0);

for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (num[grid[i][j]] == 1) {
res[0] = grid[i][j];
} else {
num[grid[i][j]] = 1;
}
}
}

for (int i = 1; i <= n * n; i++) {
if (num[i] == 0) {
res[1] = i;
break;
}
}

return res;
}
};

0 comments on commit bedda9b

Please sign in to comment.