public static int findMajorElement(int[] array, int size) {
        int counter = 0;
        int result = 0;
        for (int i = 0; i < size; i++) {
            if (counter == 0) {
                result = array[i];
            }
            if (array[i] == result) {
                counter++;
            } else {
                counter--;
            }
        }
        counter = 0;

        for (int i = 0; i < size; i++) {
            if (array[i] == result) {
                counter++;
            }
            if (counter > size / 2) {
                return result;
            }
        }
        return -1;
    }