169. 多数元素
1 class Solution 2 { 3 public: 4 int majorityElement(vector<int>& nums) 5 { 6 unordered_map<int,int> hash; 7 for(auto a : nums) hash[a]++; 8 for(auto a : hash) 9 { 10 if(a.second > nums.size()/2) return a.first; 11 } 12 return -1; 13 } 14 };
Mamba never out

浙公网安备 33010602011771号