What is unordered_set in C++
What is unordered_set in C++
下面是来自leetcode的代码块,我想知道第二行是什么意思。我从未见过这种初始化集。谁能帮忙?谢谢!
bool containsDuplicate(vector<int>& nums) {
unordered_set<int> s (nums.begin(), nums.end());
return s.size()!=nums.size();
}
unordered_set<int> s (nums.begin(), nums.end());
这通过迭代指定的vector
来初始化集合,从向量的开头开始,一直迭代直到它到达末尾,为vector
中的每个int
调用s.insert(theVal)
。
return s.size()!=nums.size();
由于unordered_set
本质上不允许集合中存在任何重复的键(即尝试将键插入集合,而该键已经是集合的成员,根本不会修改集合(,那么我们知道如果集合的最终大小小于输入向量的大小, 输入向量中必须至少有一个重复值。
相关文章:
- netcat command in c++
- Difference in displaying cv2 Mat
- C++ MFC Libraries in Travis CI
- 如何在OpenSSL中从configuration.h.in获取configuration.h
- 创建具有 new in 函数和"this is nullptr"异常的对象
- IN, OUT, INOUT Parameters
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 有人安装"IITB Simplecpp in mac"吗?
- 从 C 样式字符串中删除子字符串 "in place" 在C++代码中
- 如何修复"error: ‘_1’ was not declared in this scope"?
- Softmax Implementation in C++
- 将 out/in out 参数与 if/switch 的 init 语句一起使用
- IF-nesting in c++
- Gurobi GRBModel and GRBmodel in C++
- Tensorflow Hub in C++
- Centos7 g++ "to_string is not in a member of std"
- InitializeCriticalSectionEx Not Located In KERNEL32.Dll
- 将 lambda 表达式传递给 std::function in C++
- @CPPFLAGS@在 Makefile.in 中意味着什么?
- std::async from std::async in windows xp