#include <algorithm>
using Intpair = pair<int, int>;
class Solution {
public:
int majorityElement(vector<int>& nums) {
map<int, int> m;
for (const auto& item : nums)
m[item]++;
vector<Intpair> v(m.begin(), m.end());
sort(v.begin(), v.end(), [&](Intpair& lRef, Intpair& rRef)
{
return lRef.second < rRef.second;
});
return (*(v.end() - 1)).first;
}
};
'코딩테스트 > LeetCode' 카테고리의 다른 글
[LeetCode] Sqrt(x) (0) | 2024.03.25 |
---|---|
[LeetCode] 153. Find Minimum in Rotated Sorted Array (0) | 2024.03.05 |
[LeetCode] Remove All Adjacent Duplicates in String II (0) | 2023.12.12 |
[LeetCode] Remove All Adjacent Duplicates In String (0) | 2023.12.12 |
[LeetCode] Valid Palindrome II (0) | 2023.12.11 |