169. Majority Element Posted on 2020-09-01 | Edited on 2021-01-22 | Views: LeetCode 123456789101112131415// Time complexity: O(N)class Solution { public int majorityElement(int[] nums) { int maxCntNum=Integer.MIN_VALUE; Map<Integer,Integer> countMap=new HashMap<>(); for(int num:nums){ int cnt=countMap.getOrDefault(num,0)+1; if(cnt>nums.length/2){ maxCntNum=num; } countMap.put(num,cnt); } return maxCntNum; }}