3005.cpp 845 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <vector>
  2. #include <iostream>
  3. #include <unordered_map>
  4. int maxFrequencyElements(std::vector<int> &nums)
  5. {
  6. std::unordered_map<int,int> m;
  7. std::for_each(nums.begin(),nums.end(),[&m](int x){
  8. m[x]++;
  9. });
  10. int max = 0;
  11. for_each(m.begin(),m.end(),[&max](std::pair<int,int> p){
  12. if (p.second > max) max = p.second;
  13. });
  14. int count = 0;
  15. std::for_each(m.begin(),m.end(),[&count,max](std::pair<int,int> p){
  16. if (p.second == max) count++;
  17. });
  18. return count;
  19. }
  20. int enhance_1(std::vector<int> nums) {
  21. std::unordered_map<int,int> m;
  22. int ans = 0, max = 0;
  23. std::for_each(nums.begin(),nums.end(),[&m,&ans,&max](int x) {
  24. int c = ++m[x];
  25. if (c > max) {
  26. ans = max = c;
  27. }else if (c == max) {
  28. ans += c;
  29. }
  30. });
  31. return ans;
  32. }
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。