class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
unordered_set<int> s;
for (int x: nums) {
if (s.find(x) != s.end()) {
return true;
}
s.insert(x);
}
return false;
}
};
解题思路,首先找到此时插入x的下标值,如果之前没有相同的数值插入,则x的下标值就为现在表中的最后一个数的下标值。
存在重复数组
最新推荐文章于 2022-08-25 21:48:25 发布