-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem18.cpp
More file actions
32 lines (28 loc) · 770 Bytes
/
Copy pathproblem18.cpp
File metadata and controls
32 lines (28 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Solution {
public:
vector<int> findMissingAndRepeatedValues(vector<vector<int>>& grid) {
vector<int> ans;
unordered_set<int> s;
int a,b;
int actualsum=0;
int n=grid.size();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
actualsum += grid[i][j];
if(s.find(grid[i][j]) != s.end())
{
a=grid[i][j];
ans.push_back(a);
}
s.insert(grid[i][j]);
}
}
int expectedsum=0;
expectedsum = ((n*n) *((n*n)+1)) /2;
b = expectedsum+a-actualsum;
ans.push_back(b);
return ans;
}
};