1287. Element Appearing More Than 25% In Sorted Array

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public int findSpecialInteger(int[] arr) {
int shift = arr.length / 4;

for (int i = 0; i < arr.length; i++) {
if (arr[i + shift] == arr[i]) {
return arr[i];
}
}

return -1;
}
}

References

1287. Element Appearing More Than 25% In Sorted Array