We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2d0e0cc commit 2d69641Copy full SHA for 2d69641
cpp/0169-majority-element.cpp
@@ -7,10 +7,10 @@ The majority element is the element that appears more than ⌊n / 2⌋ times. Yo
7
class Solution {
8
public:
9
int majorityElement(vector<int>& nums) {
10
- map<int,int>mp;
11
- int n=nums.size();
12
- for(auto &i:nums){
13
- if(++mp[i]>n/2)
+ unordered_map<int, int> mp;
+ int n = nums.size();
+ for (int& i : nums){
+ if(++mp[i] > n/2)
14
return i;
15
}
16
return -1;
0 commit comments