fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class Solution {
  5. public:
  6. int findFrequency(vector<int> arr, int x) {
  7. // Your code here
  8. unordered_map<int,int>m;
  9. for(auto z:arr)m[z]++;
  10.  
  11. return m[x];
  12. }
  13. };
  14. int main() {
  15. Solution a;
  16. int n;cin>>n;
  17. int x;cin>>x;
  18. vector<int>v(n);
  19. for(int i=0;i<n;i++)cin>>v[i];
  20. cout<<a.findFrequency(v,x);
  21. return 0;
  22. }
Success #stdin #stdout 0s 5304KB
stdin
5 
1
1 1 1 1 1
stdout
5