SHARE
TWEET

Untitled

a guest Aug 18th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int firstDuplicate(std::vector<int> a) {
  2.     struct duplicate
  3.     {
  4.         int positionOfDuplicate = NULL;
  5.         int duplicateValue = NULL;
  6.     };
  7.    
  8.     duplicate duplactedNumber;
  9.    
  10.     for(int numberChecking = 0 ; numberChecking<a.size() && (numberChecking < duplactedNumber.positionOfDuplicate || duplactedNumber.positionOfDuplicate == NULL) ; numberChecking++)
  11.     {
  12.         for(int potentialDuplicate = numberChecking + 1 ; potentialDuplicate<duplactedNumber.positionOfDuplicate || potentialDuplicate < a.size();potentialDuplicate++)
  13.         {
  14.             if(a.at(numberChecking) == a.at(potentialDuplicate) && (numberChecking < duplactedNumber.positionOfDuplicate || duplactedNumber.positionOfDuplicate == NULL))
  15.             {
  16.                 duplactedNumber.positionOfDuplicate = potentialDuplicate;
  17.                 duplactedNumber.duplicateValue = a.at(potentialDuplicate);
  18.                 break;
  19.             }
  20.         }
  21.     }
  22.    
  23.     if(duplactedNumber.duplicateValue == NULL)
  24.     {
  25.         return -1;
  26.     }
  27.     else
  28.     {
  29.         return duplactedNumber.duplicateValue;        
  30.     }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top