@@ -0,0 +1,1565 @@
+/**%0A * Company%0A * Copyright (C) 2014-2017 All Rights Reserved.%0A */%0Apackage com.cwenao.trying;%0A%0A/**%0A * @author cwenao%0A * @version $Id MajorityElement.java, v 0.1 2017-07-17 9:15 cwenao Exp $$%0A */%0Apublic class MajorityElement %7B%0A%0A    private int searchMajority(int%5B%5D majArray, int size) %7B%0A        int majIndex = 0;%0A        int count = 1;%0A%0A        for(int i =1;i%3Csize;i++) %7B%0A            if (majArray%5BmajIndex%5D == majArray%5Bi%5D) %7B%0A                count++;%0A            %7D else %7B%0A                count--;%0A            %7D%0A            if (count == 0) %7B%0A                majIndex = i;%0A                count = 1;%0A            %7D%0A        %7D%0A%0A        return majArray%5BmajIndex%5D;%0A    %7D%0A%0A    private boolean isMajority(int%5B%5D majArray, int size, int maj) %7B%0A        int count = 0;%0A        for (int i=0;i%3Csize;i++) %7B%0A            if (maj == majArray%5Bi%5D) %7B%0A                count++;%0A            %7D%0A        %7D%0A        if (count %3E= size / 2) %7B%0A            return true;%0A        %7D%0A        return false;%0A    %7D%0A%0A    private void printMajority(int%5B%5D majArray, int size) %7B%0A        int maj = searchMajority(majArray, size);%0A        if (isMajority(majArray, size, maj)) %7B%0A            System.out.println(%22The majority element is : %22 + maj);%0A        %7D else %7B%0A            System.out.println(%22Have no majority element  %22);%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        MajorityElement majorityElement = new MajorityElement();%0A%0A        int%5B%5D majArray = %7B4, 3, 4, 5, 4, 3, 4, 7, 4, 8, 4%7D;%0A        int size = majArray.length;%0A        majorityElement.printMajority(majArray, size);%0A    %7D%0A%0A%7D%0A%0A

update the majority elements