package leetcode;

/**
 * https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array/
 */
public class Problem1287 {
    public int findSpecialInteger(int[] arr) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1287 prob = new Problem1287();
        System.out.println(prob.findSpecialInteger(new int[]{1,2,2,6,6,6,6,7,10})); // 6
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array/
 */
public class Problem1287 {
    public int findSpecialInteger(int[] arr) {
        int n = (int) Math.ceil(arr.length * 0.25);
        int answer = 0;
        int count = 0;
        for (int i = 0; i < arr.length - 1; i++) {
            if (arr[i] != arr[i + 1]) {
                count = 0;
            } else {
                count++;
            }
            if (count >= n) {
                return arr[i];
            }
        }
        return arr[arr.length - 1];
    }
}

Solve problem 1287