[LeetCode] Contains Duplicate

A classic problem of hash set. The unordered_set of C++ is very suitable for this problem.

The code is as follows and it should be quite self-explanatory.

1     bool containsDuplicate(vector<int>& nums) {
2         unordered_set<int> st;
3         for (int i = 0; i < nums.size(); i++) {
4             if (st.find(nums[i]) != st.end())
5                 return true;
6             st.insert(nums[i]);
7         }
8         return false;
9     }
原文地址:https://www.cnblogs.com/jcliBlogger/p/4562866.html