Skip to content

Instantly share code, notes, and snippets.

@webber2408
Created October 7, 2022 19:15
Show Gist options
  • Save webber2408/78f9194362fbd7c408574d1c0d02d696 to your computer and use it in GitHub Desktop.
Save webber2408/78f9194362fbd7c408574d1c0d02d696 to your computer and use it in GitHub Desktop.
Approach-1 Find Duplicates (Sort and find)
class Solution {
public:
int findDuplicate(vector<int>& nums) {
sort(nums.begin(), nums.end());
for (int i = 1; i < nums.size(); i++) {
if (nums[i] == nums[i - 1])
return nums[i];
}
return -1;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment