mirror of
https://github.com/20kaushik02/leetcode-gulag.git
synced 2025-12-06 09:54:07 +00:00
17 lines
302 B
C++
17 lines
302 B
C++
#include "soln.hpp"
|
|
|
|
int Solution::majorityElement(vector<int> &nums)
|
|
{
|
|
map<int, int> counts;
|
|
for (auto &it : nums)
|
|
{
|
|
counts[it]++;
|
|
if (counts[it] > (nums.size() / 2))
|
|
return it;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
bool Solution::test(vector<int>& nums, int answer) {
|
|
return majorityElement(nums) == answer;
|
|
} |