Skip to content

Instantly share code, notes, and snippets.

@webber2408
Created October 7, 2022 19:17
Show Gist options
  • Save webber2408/513b862c0d2af28f36067f1653aa41fe to your computer and use it in GitHub Desktop.
Save webber2408/513b862c0d2af28f36067f1653aa41fe to your computer and use it in GitHub Desktop.
Approach-2) Find duplicates - store in a set
class Solution {
public:
int findDuplicate(vector<int>& nums) {
unordered_set<int> seen;
for (auto &num : nums) {
if (seen.count(num))
return num;
seen.insert(num);
}
return -1;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment