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-07-21 20:39:00 发布
315

被折叠的 条评论
为什么被折叠?



