主要是记一些理解之内的东西,没理解的东西,记下来也没用,这是一个初步的总结。
更加详细的信息参考cplusplus.com
1、题目:
找出数组中重复的数字
在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。
示例 1:
- 输入:
1 | [2, 3, 1, 0, 2, 5, 3] |
- 输出:
1 | 2 或 3 |
- 限制:
1 | 2 <= n <= 100000 |
我的解决方案
1 | class Solution { |
直接使用set
的insert()
方法来进行判断当前插入的值是否已经存在,然后就此总结一下set
的相关用法。
2、关于set
2.1、Overview and feature
Sets are containers that store unique elements following a specific order.
In a
set
, the value of an element also identifies it (the value is itself the key, of typeT
), and each value must be unique. The value of the elements in aset
cannot be modified once in the container (the elements are always const), but they can be inserted or removed from the container.Internally, the elements in a
set
are always sorted following a specific strict weak ordering criterion indicated by its internal comparison object (of typeCompare
).set
containers are generally slower than unordered_set containers to access individual elements by their key, but they allow the direct iteration on subsets based on their order.Sets are typically implemented as binary search trees.
2.2、 Member functions
-
Construct set (public member function )
-
Set destructor (public member function )
-
Copy container content (public member function )
Iterators:
-
Return iterator to beginning (public member function )
-
Return iterator to end (public member function )
-
Return reverse iterator to reverse beginning (public member function )
-
Return reverse iterator to reverse end (public member function )
-
Return const_iterator to beginning (public member function )
-
Return const_iterator to end (public member function )
-
Return const_reverse_iterator to reverse beginning (public member function )
-
Return const_reverse_iterator to reverse end (public member function )
Capacity:
-
Test whether container is empty (public member function )
-
Return container size (public member function )
-
Return maximum size (public member function )
Modifiers:
-
Insert element (public member function )
-
Erase elements (public member function )
-
Swap content (public member function )
-
Clear content (public member function )
-
Construct and insert element (public member function )
-
Construct and insert element with hint (public member function )
Observers:
-
Return comparison object (public member function )
-
Return comparison object (public member function )
Operations:
-
Get iterator to element (public member function )
-
Count elements with a specific value (public member function )
-
Return iterator to lower bound (public member function )
-
Return iterator to upper bound (public member function )
-
Get range of equal elements (public member function )
Allocator:
-
Get allocator (public member function )