Skip to content

Commit

Permalink
이슈 #193에서 솔루션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 4, 2024
1 parent a9ce4ef commit d46032b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions LeetCode/Majority_Element.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#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;
}
};

0 comments on commit d46032b

Please sign in to comment.