![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
HashMap
fxy流年无悔
不要留下太多遗憾
展开
-
HashMap-数组-哈希表-面试题39. 数组中出现次数超过一半的数字
class Solution { public int majorityElement(int[] nums) { Arrays.sort(nums); return nums[nums.length/2]; } } 法二:哈希表c++ class Solution { public: int majorityElement(...原创 2020-04-19 16:37:45 · 223 阅读 · 0 评论 -
HashSet-HashMap-面试题56 - I. 数组中数字出现的次数以后统一用HashMap即可
HashSet: class Solution { public int[] singleNumbers(int[] nums) { HashSet<Integer>set=new HashSet<>(); for(int i:nums){ if(set.contains(i)) ...原创 2020-04-25 10:52:48 · 177 阅读 · 0 评论 -
HashMap-面试题56 - II. 数组中数字出现的次数 II
c++: class Solution { public: int singleNumber(vector<int>& nums) { unordered_map<int,int>mp; for(auto n:nums) mp[n]++; for(auto n:nums){ if...原创 2020-04-24 22:17:41 · 145 阅读 · 0 评论