diff --git a/2965. Find Missing and Repeated Values b/2965. Find Missing and Repeated Values new file mode 100644 index 0000000..aeea7d1 --- /dev/null +++ b/2965. Find Missing and Repeated Values @@ -0,0 +1,30 @@ +#include +using namespace std; + +class Solution { +public: + vector findMissingAndRepeatedValues(vector>& grid) { + int n = grid.size(); + vector res(2); + vector 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; + } +};