Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int firstDuplicate(std::vector<int> a) {
- struct duplicate
- {
- int positionOfDuplicate = NULL;
- int duplicateValue = NULL;
- };
- duplicate duplactedNumber;
- for(int numberChecking = 0 ; numberChecking<a.size() && (numberChecking < duplactedNumber.positionOfDuplicate || duplactedNumber.positionOfDuplicate == NULL) ; numberChecking++)
- {
- for(int potentialDuplicate = numberChecking + 1 ; potentialDuplicate<duplactedNumber.positionOfDuplicate || potentialDuplicate < a.size();potentialDuplicate++)
- {
- if(a.at(numberChecking) == a.at(potentialDuplicate) && (numberChecking < duplactedNumber.positionOfDuplicate || duplactedNumber.positionOfDuplicate == NULL))
- {
- duplactedNumber.positionOfDuplicate = potentialDuplicate;
- duplactedNumber.duplicateValue = a.at(potentialDuplicate);
- break;
- }
- }
- }
- if(duplactedNumber.duplicateValue == NULL)
- {
- return -1;
- }
- else
- {
- return duplactedNumber.duplicateValue;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement