map的find函数:
map底层是红黑树实现的,因此它的find函数时间复杂度:O(logn)
而unordered_map底层是哈希表,因此它的find函数时间复杂度:O(l)
而algorithm里的find函数是顺序查找,复杂度为O(n)
find函数:【https://blog.csdn.net/u012604810/article/details/79798082】
(不懂)iterator find ( const key_type& key );如果key存在,则find返回key对应的迭代器,如果key不存在,则find返回unordered_map::end。因此可以通过map.find(key) == map.end()来判断,key是否存在于当前的unordered_map中。
1 class Solution { 2 public: 3 // Parameters: 4 // numbers: an array of integers 5 // length: the length of array numbers 6 // duplication: (Output) the duplicated number in the array number 7 // Return value: true if the input is valid, and there are some duplications in the array number 8 // otherwise false 9 bool duplicate(int numbers[], int length, int* duplication) { 10 if (!numbers || length <= 1) 11 return false; 12 unordered_map<int,int> umap; 13 for (int i = 0; i < length; ++i) { 14 umap[numbers[i]]++; 15 if (umap[numbers[i]]>1){ 16 *duplication = numbers[i]; 17 return true; 18 } 19 } 20 return false; 21 } 22 };
https://blog.csdn.net/zjwreal/article/details/89053795(find函数不懂)
原文:https://www.cnblogs.com/wxwhnu/p/11425712.html