Repeat and Missing Number Array
1 2 3 4 5 6 7 8 9 10 11
| vector<int> vis; vector<int> Solution::repeatedNumber(const vector<int> &A) { int n = A.size(); vis = vector<int>(n + 1); int dup = -1; for(auto& a : A) if(++vis[a] == 2) dup = a; for(int i = 1; i <= n; i++) if(!vis[i]) return {dup, i}; return {dup, -1}; }
|