2965: Find-Missing-and-Repeated-Values
Easy
We need to find the duplicate
value and the
missing
value.
Code:
class Solution {
public:
<int> findMissingAndRepeatedValues(vector<vector<int>>& grid) {
vectorint n = grid.size();
int mp[2501] = {0};
int sum = 0;
int duplicate = -1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
++mp[grid[i][j]];
if (mp[grid[i][j]] == 2) {
= grid[i][j];
duplicate }
+= grid[i][j];
sum }
}
return {duplicate, (n*n)*(n*n+1)/2 - sum + duplicate};
}
};