Advertisement
peachyontop

Array

Mar 19th, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. vector<int> Solution::repeatedNumber(const vector<int> &A) {
  2.     vector<int> copy(A.size()+1, 0);
  3.     copy[0] = 1;
  4.     vector<int> ans;
  5.     for(int i = 0; i < A.size(); i++){
  6.         copy[A[i]]++;
  7.         if(copy[A[i]] > 1)
  8.             ans.push_back(A[i]);
  9.     }
  10.    
  11.     auto itr = find(copy.begin(), copy.end(), 0);
  12.     ans.push_back(itr - copy.begin());
  13.     return(ans);
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement