fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. vector<int> findDup(int a[], int len) {
  6. vector<int> ret;
  7. for (int i = 0; i<len; i++) {
  8. if(a[abs(a[i])] > 0) a[abs(a[i])] *= -1;
  9. else ret.push_back(abs(a[i]));
  10. }
  11. return ret;
  12. }
  13.  
  14. int main() {
  15. int a[] = {1,3,2,2,1};
  16. vector<int> vet;
  17. vet = findDup(a, sizeof(a)/sizeof(a[0]));
  18. for (int i:vet) cout<<i<<" ";
  19. // your code goes here
  20. return 0;
  21. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
2 1