count(): This function is available in the File: unordered_set.h
Syntax:
std::size_t std::unordered_set<int>::count(const int &__x) const
This function takes an argument of type int as its parameter. This function finds the number of elements with the specified key.
Parameters: One parameter is required for this function.
__x – Element to located.
Returns: Number of elements with the specified key. This function only makes sense for unordered_multisets; for unordered_set the result will either be 0 (not present) or 1 (present).
For Example:
st = {9.4}
x = 4
st.count(x) => It returns 1.
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){unordered_set<int> st;st.insert(9);st.insert(4);int x = 4;cout << st.count(x) << "\n";return 0;}
Output:
1
No comments:
Post a Comment