@@ -0,0 +1,969 @@
+import java.util.HashMap;%0A%0Apublic class MajorityElement %7B%0A    /**%0A    Given an array of size n, find the majority element. The majority element is the element that appears more than %E2%8C%8A n/2 %E2%8C%8B times.%0A    You may assume that the array is non-empty and the majority element always exist in the array.%0A    */%0A    public int majorityElement(int%5B%5D nums) %7B%0A        int majority = 0;%0A        HashMap%3CInteger, Integer%3E freq = new HashMap%3C%3E ();%0A        for (int num : nums) %7B%0A            int count = freq.containsKey(num) ? freq.get(num) : 0;%0A            if (count + 1 %3E nums.length / 2) %7B%0A                majority = num; %0A                break;%0A            %7D%0A            freq.put (num, count + 1);%0A        %7D%0A        return majority;%0A    %7D%0A    %0A    public static void main (String%5B%5D args) %7B%0A        MajorityElement test = new MajorityElement ();%0A        int%5B%5D nums = %7B12, 13, 12, 1, 12, 12, 12, 14, 12, 15, 12, 12%7D;%0A        System.out.println (test.majorityElement (nums));%0A    %7D%0A%7D

Find majority element in array