Skip to content

Commit 2d69641

Browse files
authored
Substituted map with unordered_map and reindented
1 parent 2d0e0cc commit 2d69641

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cpp/0169-majority-element.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ The majority element is the element that appears more than ⌊n / 2⌋ times. Yo
77
class Solution {
88
public:
99
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)
10+
unordered_map<int, int> mp;
11+
int n = nums.size();
12+
for (int& i : nums){
13+
if(++mp[i] > n/2)
1414
return i;
1515
}
1616
return -1;

0 commit comments

Comments
 (0)