-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
#include <unordered_map>
class Solution {
public:
int majorityElement(vector<int>& nums) {
unordered_map<int, int> m;
for (int num : nums) {
m[num]++;
}
int maxCount = 0;
int maxNum = 0;
for (auto pair : m) {
if (pair.second > maxCount) {
maxNum = pair.first;
maxCount = pair.second;
}
}
return maxNum;
}
};- map으로 풀거나 정렬한 뒤에 개수 찾기
Metadata
Metadata
Assignees
Labels
Projects
Status
Done