Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int majorityElement(vector<int>& nums) {
- int n=nums.size();
- unordered_map<int,int> m;
- for(int i=0;i<nums.size();i++)
- {
- m[nums[i]]++;
- }
- int mx = -1;
- int mx_ele;
- for(auto u:m)
- {
- if(u.second>mx)
- {
- mx=u.second;
- mx_ele=u.first;
- }
- }
- int ans = floor(n/2);
- return mx_ele;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment