Skip to content

Create 2965. Find Missing and Repeated Values #732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
};
Loading