Solutions to high-frequency interview questions of LeetCode in C++17, taking into account both efficiency and comprehensibility.
O(n)
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
unordered_set<int> s;
for (auto& x : nums) {
if (s.count(x)) {
return true;
}
s.emplace(x);
}
return false;
}
};